File tree 2 files changed +47
-1
lines changed
2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change
1
+ //
2
+ // UpdateJobDelay.swift
3
+ // swift-jobs-postgres
4
+ //
5
+ // Created by Stevenson Michel on 2/17/25.
6
+ //
7
+
8
+ //===----------------------------------------------------------------------===//
9
+ //
10
+ // This source file is part of the Hummingbird server framework project
11
+ //
12
+ // Copyright (c) 2024 the Hummingbird authors
13
+ // Licensed under Apache License v2.0
14
+ //
15
+ // See LICENSE.txt for license information
16
+ // See hummingbird/CONTRIBUTORS.txt for the list of Hummingbird authors
17
+ //
18
+ // SPDX-License-Identifier: Apache-2.0
19
+ //
20
+ //===----------------------------------------------------------------------===//
21
+
22
+ import Logging
23
+ import PostgresMigrations
24
+ import PostgresNIO
25
+
26
+ struct UpdateJobDelay : DatabaseMigration {
27
+ func apply( connection: PostgresConnection , logger: Logger ) async throws {
28
+ try await connection. query (
29
+ """
30
+ ALTER TABLE _hb_pg_job_queue ALTER COLUMN delayed_until TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
31
+ """ ,
32
+ logger: logger
33
+ )
34
+ }
35
+
36
+ func revert( connection: PostgresConnection , logger: Logger ) async throws {
37
+ try await connection. query (
38
+ " ALTER TABLE _hb_pg_job_queue ALTER COLUMN delayed_until DROP NOT NULL " ,
39
+ logger: logger
40
+ )
41
+ }
42
+
43
+ var name : String { " _Update_JobQueueDelay_Table_ " }
44
+ var group : DatabaseMigrationGroup { . jobQueue }
45
+ }
Original file line number Diff line number Diff line change @@ -112,6 +112,7 @@ public final class PostgresJobQueue: JobQueueDriver {
112
112
await migrations. add ( CreateJobQueue ( ) )
113
113
await migrations. add ( CreateJobQueueMetadata ( ) )
114
114
await migrations. add ( CreateJobDelay ( ) )
115
+ await migrations. add ( UpdateJobDelay ( ) )
115
116
}
116
117
117
118
/// Run on initialization of the job queue
@@ -203,7 +204,7 @@ public final class PostgresJobQueue: JobQueueDriver {
203
204
SELECT
204
205
job_id
205
206
FROM _hb_pg_job_queue
206
- WHERE ( delayed_until IS NULL OR delayed_until <= NOW() )
207
+ WHERE delayed_until <= NOW()
207
208
ORDER BY createdAt, delayed_until ASC
208
209
FOR UPDATE SKIP LOCKED
209
210
LIMIT 1
You can’t perform that action at this time.
0 commit comments