@@ -46,7 +46,7 @@ public final class PostgresJobQueue: JobQueueDriver {
46
46
public typealias JobID = UUID
47
47
48
48
/// what to do with failed/processing jobs from last time queue was handled
49
- public enum JobInitialization : Sendable {
49
+ public enum JobCleanup : Sendable {
50
50
case doNothing
51
51
case rerun
52
52
case remove
@@ -73,8 +73,11 @@ public final class PostgresJobQueue: JobQueueDriver {
73
73
74
74
/// Queue configuration
75
75
public struct Configuration : Sendable {
76
+ /// Queue poll time to wait if queue empties
76
77
let pollTime : Duration
77
78
79
+ /// Initialize configuration
80
+ /// - Parameter pollTime: Queue poll time to wait if queue empties
78
81
public init (
79
82
pollTime: Duration = . milliseconds( 100 )
80
83
) {
@@ -107,15 +110,27 @@ public final class PostgresJobQueue: JobQueueDriver {
107
110
}
108
111
109
112
/// Cleanup job queues
113
+ ///
114
+ /// This function is used to re-run or delete jobs in a certain state. Failed jobs can be
115
+ /// pushed back into the pending queue to be re-run or removed. When called at startup in
116
+ /// theory no job should be set to processing, or set to pending but not in the queue. but if
117
+ /// your job server crashes these states are possible, so we also provide options to re-queue
118
+ /// these jobs so they are run again.
119
+ ///
120
+ /// The job queue needs to be running when you call cleanup. You can call `cleanup` with
121
+ /// `failedJobs`` set to whatever you like at any point to re-queue failed jobs. Moving processing
122
+ /// or pending jobs should only be done if you are certain there is nothing else processing
123
+ /// the job queue.
124
+ ///
110
125
/// - Parameters:
111
126
/// - failedJobs: What to do with jobs tagged as failed
112
127
/// - processingJobs: What to do with jobs tagged as processing
113
128
/// - pendingJobs: What to do with jobs tagged as pending
114
129
/// - Throws:
115
130
public func cleanup(
116
- failedJobs: JobInitialization = . doNothing,
117
- processingJobs: JobInitialization = . doNothing,
118
- pendingJobs: JobInitialization = . doNothing
131
+ failedJobs: JobCleanup = . doNothing,
132
+ processingJobs: JobCleanup = . doNothing,
133
+ pendingJobs: JobCleanup = . doNothing
119
134
) async throws {
120
135
do {
121
136
self . logger. info ( " Waiting for JobQueue migrations " )
@@ -315,7 +330,7 @@ public final class PostgresJobQueue: JobQueueDriver {
315
330
return jobs
316
331
}
317
332
318
- func updateJobsOnInit( withStatus status: Status , onInit: JobInitialization , connection: PostgresConnection ) async throws {
333
+ func updateJobsOnInit( withStatus status: Status , onInit: JobCleanup , connection: PostgresConnection ) async throws {
319
334
switch onInit {
320
335
case . remove:
321
336
try await connection. query (
0 commit comments