@@ -51,13 +51,38 @@ public final class PostgresJobQueue: JobQueueDriver {
51
51
case remove
52
52
}
53
53
54
- /// Job priority
55
- public enum JobPriority : Int16 , Sendable , PostgresCodable {
56
- case lowest = 0
57
- case lower = 1
58
- case normal = 2
59
- case higher = 3
60
- case highest = 4
54
+ /// Job priority from lowest to highest
55
+ public struct JobPriority : Equatable , Sendable {
56
+ let rawValue : Priority
57
+
58
+ // Job priority
59
+ enum Priority : Int16 , Sendable , PostgresCodable {
60
+ case lowest = 0
61
+ case lower = 1
62
+ case normal = 2
63
+ case higher = 3
64
+ case highest = 4
65
+ }
66
+ /// Lowest priority
67
+ public static func lowest( ) -> JobPriority {
68
+ JobPriority ( rawValue: . lowest)
69
+ }
70
+ /// Lower priority
71
+ public static func lower( ) -> JobPriority {
72
+ JobPriority ( rawValue: . lower)
73
+ }
74
+ /// Normal is the default priority
75
+ public static func normal( ) -> JobPriority {
76
+ JobPriority ( rawValue: . normal)
77
+ }
78
+ /// Higher priority
79
+ public static func higher( ) -> JobPriority {
80
+ JobPriority ( rawValue: . higher)
81
+ }
82
+ /// Higgest priority
83
+ public static func highest( ) -> JobPriority {
84
+ JobPriority ( rawValue: . highest)
85
+ }
61
86
}
62
87
63
88
/// Options for job pushed to queue
@@ -70,20 +95,20 @@ public final class PostgresJobQueue: JobQueueDriver {
70
95
/// Default initializer for JobOptions
71
96
public init ( ) {
72
97
self . delayUntil = . now
73
- self . priority = . normal
98
+ self . priority = . normal( )
74
99
}
75
100
76
101
/// Initializer for JobOptions
77
102
/// - Parameter delayUntil: Whether job execution should be delayed until a later date
78
103
public init ( delayUntil: Date ? ) {
79
104
self . delayUntil = delayUntil ?? . now
80
- self . priority = . normal
105
+ self . priority = . normal( )
81
106
}
82
107
83
108
/// Initializer for JobOptions
84
109
/// - Parameter delayUntil: Whether job execution should be delayed until a later date
85
110
/// - Parameter priority: The priority for a job
86
- public init ( delayUntil: Date = . now, priority: JobPriority = . normal) {
111
+ public init ( delayUntil: Date = . now, priority: JobPriority = . normal( ) ) {
87
112
self . delayUntil = delayUntil
88
113
self . priority = priority
89
114
}
@@ -411,7 +436,7 @@ public final class PostgresJobQueue: JobQueueDriver {
411
436
try await connection. query (
412
437
"""
413
438
INSERT INTO swift_jobs.queues (job_id, created_at, delayed_until, queue_name, priority)
414
- VALUES ( \( jobID) , \( Date . now) , \( options. delayUntil) , \( queueName) , \( options. priority) )
439
+ VALUES ( \( jobID) , \( Date . now) , \( options. delayUntil) , \( queueName) , \( options. priority. rawValue ) )
415
440
-- We have found an existing job with the same id, SKIP this INSERT
416
441
ON CONFLICT (job_id) DO NOTHING
417
442
""" ,
0 commit comments