1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use std::time::Duration;
use super::WorkerOptions;
use graphile_worker_database::Schema;
impl WorkerOptions {
/// Sets the PostgreSQL schema name for Graphile Worker tables.
///
/// Isolates Graphile Worker tables in a separate schema,
/// which keeps the database organized or allows running multiple
/// independent worker instances in the same database.
///
/// # Arguments
/// * `value` - The schema name to use
///
/// # Default
/// If not specified, the schema name defaults to "graphile_worker".
pub fn schema(mut self, value: impl Into<Schema>) -> Self {
self.schema = Some(value.into());
self
}
/// Sets the number of jobs that can be processed concurrently.
///
/// Controls how many jobs the worker processes simultaneously.
/// Setting an appropriate concurrency level depends on workload:
/// - CPU-intensive tasks: Set close to the number of cores
/// - I/O-intensive tasks: Can often use higher values (10-20+)
///
/// # Arguments
/// * `value` - The maximum number of concurrent jobs
///
/// # Default
/// If not specified, defaults to the number of logical CPUs in the system.
///
/// # Panics
/// Panics if the value is 0, as at least one job must be processable.
pub fn concurrency(mut self, value: usize) -> Self {
assert!(value > 0, "Concurrency must be greater than 0");
self.concurrency = Some(value);
self
}
/// Sets how often the worker checks the database for new jobs.
///
/// Controls the polling interval for checking for new jobs when
/// PostgreSQL notification delivery fails or for jobs scheduled in the future.
///
/// # Arguments
/// * `value` - The interval between database polls
///
/// # Default
/// If not specified, defaults to 1000 milliseconds (1 second).
///
/// # Note
/// Lower values increase responsiveness but may increase database load.
/// For most applications, the default value is appropriate.
pub fn poll_interval(mut self, value: Duration) -> Self {
self.poll_interval = Some(value);
self
}
/// Sets whether to use PostgreSQL notification delivery.
///
/// # Arguments
/// * `value` - True to use notification delivery, false to use polling only
///
/// # Default
/// If not specified, defaults to true
pub fn use_notification_delivery(mut self, value: bool) -> Self {
self.use_notification_delivery = Some(value);
self
}
/// Sets whether to use local application time or database time for timestamps.
///
/// When `use_local_time` is true, the application's `Utc::now()` is used for timestamps,
/// which can help handle clock drift between the application server and database server.
/// When false (default), PostgreSQL's `now()` is used instead.
///
/// Affects job fetching, job scheduling, and crontab scheduling.
///
/// # Arguments
/// * `value` - True to use application time, false to use database time
///
/// # Default
/// If not specified, defaults to false (use PostgreSQL server time).
///
/// # Note
/// Using PostgreSQL server time is recommended for consistent behavior
/// across multiple worker instances, especially in distributed deployments.
pub fn use_local_time(mut self, value: bool) -> Self {
self.use_local_time = value;
self
}
}