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: StringThe 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: StringThe consumer group the worker reads it with, such as hash_workers, created when missing.
consumer: StringThis worker’s consumer name, unique within the group, and the worker_id of its results.
result_stream: StringWhere 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: boolSend 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: usizeHow many tasks run at once, each on a thread of its own. 1 by default.
read_block: DurationHow long one read waits for a task; also the longest a stop waits for a read in progress. 5 s by default.
lease_heartbeat: DurationHow 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: DurationHow 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: u64How 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: DurationHow long a stop waits for running tasks before it releases them to other workers. 30 s by default.
flush_attempts: u32How 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: DurationThe wait before the second attempt; each later one waits that much longer. 2 s by default.
limits: LimitsThe bounds on a task the worker reads and a result it writes.
Implementations§
Source§impl WorkerConfig
impl WorkerConfig
Sourcepub fn new(
stream: impl Into<String>,
group: impl Into<String>,
consumer: impl Into<String>,
result_stream: impl Into<String>,
) -> Self
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);