Skip to main content

ff_sdk/
config.rs

1use ff_core::backend::BackendConfig;
2use ff_core::partition::PartitionConfig;
3use ff_core::types::{LaneId, Namespace, WorkerId, WorkerInstanceId};
4
5/// Configuration for a FlowFabric worker.
6///
7/// **RFC-012 Stage 1c tranche 1.** Valkey-specific connection
8/// parameters (`host`, `port`, `tls`, `cluster`) moved to the nested
9/// [`BackendConfig`] field, which also carries
10/// [`BackendTimeouts`](ff_core::backend::BackendTimeouts) and
11/// [`BackendRetry`](ff_core::backend::BackendRetry) policy. Build one
12/// with [`BackendConfig::valkey`] for the common standalone case; for
13/// TLS / cluster / tuned retry, construct the
14/// [`ValkeyConnection`](ff_core::backend::ValkeyConnection) and
15/// [`BackendConfig`] fields directly.
16///
17/// Worker-policy fields (`lease_ttl_ms`, `claim_poll_interval_ms`,
18/// capability set, lane list, identity) stay on `WorkerConfig` —
19/// those are orthogonal to the storage backend choice.
20///
21/// `WorkerConfig::new` was removed in this stage (pre-1.0 clean
22/// break); construct via struct literal.
23pub struct WorkerConfig {
24    /// Backend connection + shared timeouts / retry policy.
25    pub backend: BackendConfig,
26    /// Logical worker identity (e.g., "gpu-worker-pool-1").
27    pub worker_id: WorkerId,
28    /// Concrete worker process/runtime instance identity (e.g., container ID).
29    pub worker_instance_id: WorkerInstanceId,
30    /// Namespace this worker operates in.
31    pub namespace: Namespace,
32    /// Lanes this worker claims work from.
33    pub lanes: Vec<LaneId>,
34    /// Capabilities this worker advertises for routing.
35    pub capabilities: Vec<String>,
36    /// Lease TTL in milliseconds. Default: 30,000 (30s).
37    pub lease_ttl_ms: u64,
38    /// Interval between claim attempts when idle, in milliseconds. Default: 1,000 (1s).
39    pub claim_poll_interval_ms: u64,
40    /// Maximum concurrent tasks. Default: 1.
41    pub max_concurrent_tasks: usize,
42    /// Override for the server-published partition config.
43    ///
44    /// v0.12 PR-6: closes the follow-up flagged in
45    /// [`FlowFabricWorker::connect_with`]'s pre-PR-6 rustdoc
46    /// ("callers needing a non-default `PartitionConfig` under
47    /// non-Valkey backends use `connect` (Valkey) or override
48    /// post-construction through a future `WorkerConfig` field").
49    ///
50    /// * `None` (default) — `connect_with` uses
51    ///   [`PartitionConfig::default()`] (256 / 32 / 32);
52    ///   `connect` ignores this field and reads
53    ///   `ff:config:partitions` from Valkey as before.
54    /// * `Some(cfg)` — `connect_with` binds the worker to `cfg`
55    ///   directly; `connect` still prefers Valkey's published
56    ///   hash (this override is a `connect_with`-only knob, since
57    ///   Valkey's `ff:config:partitions` is authoritative when
58    ///   present).
59    ///
60    /// Consumers using a PG / SQLite backend whose deployment
61    /// uses a non-default `num_flow_partitions` (e.g. 512) must
62    /// set this — otherwise `describe_execution` + partition-
63    /// keyed claim paths compute the wrong partition index and
64    /// silently miss data.
65    ///
66    /// [`FlowFabricWorker::connect_with`]: crate::FlowFabricWorker::connect_with
67    pub partition_config: Option<PartitionConfig>,
68}
69
70impl WorkerConfig {
71    /// Lease renewal interval: TTL / 3 (renew at 1/3 of TTL, leaving 2/3 margin).
72    pub fn renewal_interval_ms(&self) -> u64 {
73        self.lease_ttl_ms / 3
74    }
75}