ff_sdk/config.rs
1use ff_core::types::{LaneId, Namespace, WorkerId, WorkerInstanceId};
2
3/// Configuration for a FlowFabric worker.
4pub struct WorkerConfig {
5 /// Valkey hostname. Default: `"localhost"`.
6 pub host: String,
7 /// Valkey port. Default: `6379`.
8 pub port: u16,
9 /// Enable TLS for the Valkey connection.
10 pub tls: bool,
11 /// Enable Valkey cluster mode.
12 pub cluster: bool,
13 /// Logical worker identity (e.g., "gpu-worker-pool-1").
14 pub worker_id: WorkerId,
15 /// Concrete worker process/runtime instance identity (e.g., container ID).
16 pub worker_instance_id: WorkerInstanceId,
17 /// Namespace this worker operates in.
18 pub namespace: Namespace,
19 /// Lanes this worker claims work from.
20 pub lanes: Vec<LaneId>,
21 /// Capabilities this worker advertises for routing.
22 pub capabilities: Vec<String>,
23 /// Lease TTL in milliseconds. Default: 30,000 (30s).
24 pub lease_ttl_ms: u64,
25 /// Interval between claim attempts when idle, in milliseconds. Default: 1,000 (1s).
26 pub claim_poll_interval_ms: u64,
27 /// Maximum concurrent tasks. Default: 1.
28 pub max_concurrent_tasks: usize,
29}
30
31impl WorkerConfig {
32 /// Create a minimal config for a single-lane worker.
33 pub fn new(
34 host: impl Into<String>,
35 port: u16,
36 worker_id: impl Into<String>,
37 worker_instance_id: impl Into<String>,
38 namespace: impl Into<String>,
39 lane: impl Into<String>,
40 ) -> Self {
41 Self {
42 host: host.into(),
43 port,
44 tls: false,
45 cluster: false,
46 worker_id: WorkerId::new(worker_id),
47 worker_instance_id: WorkerInstanceId::new(worker_instance_id),
48 namespace: Namespace::new(namespace),
49 lanes: vec![LaneId::new(lane)],
50 capabilities: Vec::new(),
51 lease_ttl_ms: 30_000,
52 claim_poll_interval_ms: 1_000,
53 max_concurrent_tasks: 1,
54 }
55 }
56
57 /// Lease renewal interval: TTL / 3 (renew at 1/3 of TTL, leaving 2/3 margin).
58 pub fn renewal_interval_ms(&self) -> u64 {
59 self.lease_ttl_ms / 3
60 }
61}