graphile_worker_lifecycle_hooks/
context.rs1use std::sync::Arc;
2use std::time::Duration;
3
4use chrono::{DateTime, Utc};
5use graphile_worker_crontab_types::Crontab;
6use graphile_worker_extensions::ReadOnlyExtensions;
7use graphile_worker_job::Job;
8use graphile_worker_job_spec::JobSpec;
9use sqlx::PgPool;
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub enum ShutdownReason {
13 Signal,
14 Error,
15 Graceful,
16}
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum LocalQueueMode {
20 Starting,
21 Polling,
22 Waiting,
23 TtlExpired,
24 Released,
25}
26
27#[derive(Clone)]
28pub struct WorkerInitContext {
29 pub pool: PgPool,
30 pub schema: String,
31 pub concurrency: usize,
32}
33
34#[derive(Clone)]
35pub struct WorkerStartContext {
36 pub pool: PgPool,
37 pub worker_id: String,
38 pub extensions: ReadOnlyExtensions,
39}
40
41#[derive(Clone)]
42pub struct WorkerShutdownContext {
43 pub pool: PgPool,
44 pub worker_id: String,
45 pub reason: ShutdownReason,
46}
47
48#[derive(Clone)]
49pub struct JobFetchContext {
50 pub job: Arc<Job>,
51 pub worker_id: String,
52}
53
54#[derive(Clone)]
55pub struct JobStartContext {
56 pub job: Arc<Job>,
57 pub worker_id: String,
58}
59
60#[derive(Clone)]
61pub struct JobCompleteContext {
62 pub job: Arc<Job>,
63 pub worker_id: String,
64 pub duration: Duration,
65}
66
67#[derive(Clone)]
68pub struct JobFailContext {
69 pub job: Arc<Job>,
70 pub worker_id: String,
71 pub error: String,
72 pub will_retry: bool,
73}
74
75#[derive(Clone)]
76pub struct JobPermanentlyFailContext {
77 pub job: Arc<Job>,
78 pub worker_id: String,
79 pub error: String,
80}
81
82#[derive(Clone)]
83pub struct BeforeJobRunContext {
84 pub job: Arc<Job>,
85 pub worker_id: String,
86 pub payload: serde_json::Value,
87}
88
89#[derive(Clone)]
90pub struct AfterJobRunContext {
91 pub job: Arc<Job>,
92 pub worker_id: String,
93 pub result: Result<(), String>,
94 pub duration: Duration,
95}
96
97#[derive(Clone)]
98pub struct CronTickContext {
99 pub timestamp: DateTime<Utc>,
100 pub crontabs: Vec<Crontab>,
101}
102
103#[derive(Clone)]
104pub struct CronJobScheduledContext {
105 pub crontab: Crontab,
106 pub scheduled_at: DateTime<Utc>,
107}
108
109#[derive(Clone)]
110pub struct BeforeJobScheduleContext {
111 pub identifier: String,
112 pub payload: serde_json::Value,
113 pub spec: JobSpec,
114}
115
116#[derive(Debug, Clone)]
117pub struct LocalQueueInitContext {
118 pub worker_id: String,
119}
120
121#[derive(Debug, Clone)]
122pub struct LocalQueueSetModeContext {
123 pub worker_id: String,
124 pub old_mode: LocalQueueMode,
125 pub new_mode: LocalQueueMode,
126}
127
128#[derive(Debug, Clone)]
129pub struct LocalQueueGetJobsCompleteContext {
130 pub worker_id: String,
131 pub jobs_count: usize,
132}
133
134#[derive(Debug, Clone)]
135pub struct LocalQueueReturnJobsContext {
136 pub worker_id: String,
137 pub jobs_count: usize,
138}
139
140#[derive(Debug, Clone)]
141pub struct LocalQueueRefetchDelayStartContext {
142 pub worker_id: String,
143 pub duration: Duration,
144 pub threshold: usize,
145 pub abort_threshold: usize,
146}
147
148#[derive(Debug, Clone)]
149pub struct LocalQueueRefetchDelayAbortContext {
150 pub worker_id: String,
151 pub count: usize,
152 pub abort_threshold: usize,
153}
154
155#[derive(Debug, Clone)]
156pub struct LocalQueueRefetchDelayExpiredContext {
157 pub worker_id: String,
158}