pub struct DistributedEncoder { /* private fields */ }Expand description
Main distributed encoder interface.
Maintains an in-process job store so that submit_job, job_status, and
cancel_job operate on real state. In a production deployment the store
would be backed by the gRPC coordinator; this implementation provides a
fully functional local fallback that exercises the complete lifecycle.
When config.coordinator_addr is non-empty, a background coordinator
server is started on that address so workers can connect and register.
Implementations§
Source§impl DistributedEncoder
impl DistributedEncoder
Sourcepub fn new(config: DistributedConfig) -> Self
pub fn new(config: DistributedConfig) -> Self
Create a new distributed encoder with the given configuration.
If config.coordinator_addr is non-empty and parses as a valid
std::net::SocketAddr, a background coordinator::Coordinator
server is spawned on that address so remote workers can connect.
Failures to bind are logged as warnings and degrade gracefully —
the local job store remains fully functional regardless.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a new distributed encoder with default configuration
Sourcepub fn config(&self) -> &DistributedConfig
pub fn config(&self) -> &DistributedConfig
Get the current configuration
Sourcepub async fn active_job_count(&self) -> usize
pub async fn active_job_count(&self) -> usize
Return the number of active (non-terminal) jobs.
Sourcepub async fn submit_job(&self, job: DistributedJob) -> Result<Uuid>
pub async fn submit_job(&self, job: DistributedJob) -> Result<Uuid>
Submit a job for distributed encoding.
Validates the job, checks concurrency limits, registers it in the internal store, and returns the job ID on success.
§Arguments
job- The encoding job to submit
§Returns
Returns the job ID on success
§Errors
Returns DistributedError::InvalidConfig if the job definition is
invalid, or DistributedError::ResourceExhausted if the maximum
concurrent job limit has been reached.
Sourcepub async fn job_status(&self, job_id: Uuid) -> Result<JobStatus>
pub async fn job_status(&self, job_id: Uuid) -> Result<JobStatus>
Query the status of a previously submitted job.
In addition to returning the stored status, this method performs
timeout checking: if a job has been active longer than the configured
job_timeout it is automatically marked as Failed.
§Errors
Returns DistributedError::Job if the job ID is not found.
Sourcepub async fn cancel_job(&self, job_id: Uuid) -> Result<()>
pub async fn cancel_job(&self, job_id: Uuid) -> Result<()>
Cancel a previously submitted job.
Only jobs that are not yet in a terminal state (Completed, Failed,
Cancelled) can be cancelled.
§Errors
Returns DistributedError::Job if the job ID is not found or the job
is already in a terminal state.
Sourcepub async fn advance_job(&self, job_id: Uuid) -> Result<JobStatus>
pub async fn advance_job(&self, job_id: Uuid) -> Result<JobStatus>
Advance a job to the next logical status (for internal/testing use).
Transitions: Pending -> Assigned -> InProgress -> Completed
§Errors
Returns error if the job is not found or is in a terminal state.
Sourcepub async fn fail_job(&self, job_id: Uuid) -> Result<()>
pub async fn fail_job(&self, job_id: Uuid) -> Result<()>
Mark a job as failed (for internal/testing use).
§Errors
Returns error if the job is not found or already in a terminal state.
Sourcepub async fn job_retries(&self, job_id: Uuid) -> Result<u32>
pub async fn job_retries(&self, job_id: Uuid) -> Result<u32>
Sourcepub async fn list_jobs(&self) -> Vec<(Uuid, JobStatus)>
pub async fn list_jobs(&self) -> Vec<(Uuid, JobStatus)>
List all job IDs with their current statuses.
Sourcepub async fn submit_jobs_batch(
&self,
jobs: Vec<DistributedJob>,
) -> Vec<Result<Uuid>> ⓘ
pub async fn submit_jobs_batch( &self, jobs: Vec<DistributedJob>, ) -> Vec<Result<Uuid>> ⓘ
Submit a batch of jobs atomically.
Attempts to submit each job in jobs in order. Returns a parallel
Vec of Result<Uuid> — one entry per submitted job. Jobs that fail
validation or exceed the concurrency limit produce Err entries;
successful jobs produce Ok(job_id).
The batch is not transactional: successful jobs submitted earlier in the slice are committed even if a later job fails.
Trait Implementations§
Source§impl Drop for DistributedEncoder
impl Drop for DistributedEncoder
Auto Trait Implementations§
impl !RefUnwindSafe for DistributedEncoder
impl !UnwindSafe for DistributedEncoder
impl Freeze for DistributedEncoder
impl Send for DistributedEncoder
impl Sync for DistributedEncoder
impl Unpin for DistributedEncoder
impl UnsafeUnpin for DistributedEncoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request