Skip to main content

WorkerConfig

Struct WorkerConfig 

Source
pub struct WorkerConfig {
Show 14 fields pub stream: String, pub group: String, pub consumer: String, pub result_stream: String, pub route_results_per_app: bool, pub concurrency: usize, pub read_block: Duration, pub lease_heartbeat: Duration, pub claim_idle: Duration, pub max_deliveries: u64, pub shutdown_grace: Duration, pub flush_attempts: u32, pub flush_backoff: Duration, pub limits: Limits,
}
Expand description

The settings of a Worker. The defaults are the contract’s reference values, where it gives one; a deployment may change them. What the contract fixes is that the heartbeat is at most a third of the claim threshold and that every worker on a group uses the same threshold.

use std::time::Duration;
use legit_streams::WorkerConfig;

let config = WorkerConfig {
    concurrency: 4,
    ..WorkerConfig::new("hash_tasks", "hash_workers", "worker-1", "hash_results")
};
assert_eq!(config.lease_heartbeat, Duration::from_secs(60));

Fields§

§stream: String

The task stream, such as hash_tasks. It can’t begin with results: or dead:, the names of result streams and of tasks an operator has set aside.

§group: String

The consumer group the worker reads it with, such as hash_workers, created when missing.

§consumer: String

This worker’s consumer name, unique within the group, and the worker_id of its results.

§result_stream: String

Where the result of a task that names no valid reply_to goes, such as hash_results, and every result when WorkerConfig::route_results_per_app is off.

§route_results_per_app: bool

Send each result to the stream its task’s reply_to names. On by default, as the contract asks: a worker honours a task’s reply_to, and uses result_stream only for a task that names none. A task whose reply_to fails is_valid_reply_to still runs, and its result, success or error, goes to result_stream, with a warning in the log.

Turn it off only on an instance with a single application: with more than one, every producer must send reply_to and every worker must honour it.

§concurrency: usize

How many tasks run at once, each on a thread of its own. 1 by default.

§read_block: Duration

How long one read waits for a task; also the longest a stop waits for a read in progress. 5 s by default.

§lease_heartbeat: Duration

How often the worker renews the lease on each task it runs, so no other worker claims it. 60 s by default, the contract’s reference value; at most a third of WorkerConfig::claim_idle, so a worker can miss two renewals before another claims its task.

§claim_idle: Duration

How long an entry must sit unrenewed before this worker claims it from another, presumed dead. 300 s by default, the contract’s reference value. It belongs to the group, not the worker: every worker reading a group must use the same value, or one with a shorter threshold claims tasks that another’s heartbeat keeps alive.

§max_deliveries: u64

How many deliveries a task may have: it runs on deliveries 1 to max_deliveries. A task whose delivery count is more than this when a worker takes it is answered with a max_deliveries_exceeded error rather than run again. 3 by default, the contract’s default.

§shutdown_grace: Duration

How long a stop waits for running tasks before it releases them to other workers. 30 s by default.

§flush_attempts: u32

How many times the worker tries to write a result, and then to acknowledge the task, before it leaves the task pending for another worker. 5 by default.

§flush_backoff: Duration

The wait before the second attempt; each later one waits that much longer. 2 s by default.

§limits: Limits

The bounds on a task the worker reads and a result it writes.

Implementations§

Source§

impl WorkerConfig

Source

pub fn new( stream: impl Into<String>, group: impl Into<String>, consumer: impl Into<String>, result_stream: impl Into<String>, ) -> Self

The default settings for reading stream with group as consumer, replying to result_stream.

use legit_streams::WorkerConfig;

let config = WorkerConfig::new("hash_tasks", "hash_workers", "worker-1", "hash_results");
assert_eq!(config.concurrency, 1);
assert!(config.route_results_per_app);
assert_eq!(config.max_deliveries, 3);

Trait Implementations§

Source§

impl Clone for WorkerConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WorkerConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for WorkerConfig

Source§

impl PartialEq for WorkerConfig

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for WorkerConfig

Auto Trait Implementations§

§

impl Forget for WorkerConfig

§

impl Freeze for WorkerConfig
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for WorkerConfig

§

impl RefUnwindSafe for WorkerConfig

§

impl Send for WorkerConfig
where RawVecInner: Send,

§

impl Sync for WorkerConfig
where RawVecInner: Sync,

§

impl Unpin for WorkerConfig
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for WorkerConfig

§

impl UnwindSafe for WorkerConfig
where RawVecInner: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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