Skip to main content

DistributedEncoder

Struct DistributedEncoder 

Source
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

Source

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.

Source

pub fn with_defaults() -> Self

Create a new distributed encoder with default configuration

Source

pub fn config(&self) -> &DistributedConfig

Get the current configuration

Source

pub async fn job_count(&self) -> usize

Return the number of currently tracked jobs.

Source

pub async fn active_job_count(&self) -> usize

Return the number of active (non-terminal) jobs.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn job_retries(&self, job_id: Uuid) -> Result<u32>

Get the retry count for a job.

§Errors

Returns error if the job is not found.

Source

pub async fn list_jobs(&self) -> Vec<(Uuid, JobStatus)>

List all job IDs with their current statuses.

Source

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

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more