@@ -173,6 +173,14 @@ public final class PostgresJobQueue: JobQueueDriver {
173
173
}
174
174
}
175
175
176
+ @discardableResult public func update( _ id: JobID , buffer: ByteBuffer , options: JobOptions ) async throws -> Bool {
177
+ try await self . client. withTransaction ( logger: self . logger) { connection in
178
+ try await self . update ( id: id, buffer: buffer, connection: connection)
179
+ try await self . updateQueue ( jobId: id, connection: connection, delayUntil: options. delayUntil)
180
+ }
181
+ return true
182
+ }
183
+
176
184
/// This is called to say job has finished processing and it can be deleted
177
185
public func finished( jobId: JobID ) async throws {
178
186
try await self . delete ( jobId: jobId)
@@ -295,6 +303,19 @@ public final class PostgresJobQueue: JobQueueDriver {
295
303
logger: self . logger
296
304
)
297
305
}
306
+ /// TODO maybe add a new column colum for attempt so far after PR https://github.com/hummingbird-project/swift-jobs/pull/63 is merged?
307
+ func update( id: JobID , buffer: ByteBuffer , connection: PostgresConnection ) async throws {
308
+ try await connection. query (
309
+ """
310
+ UPDATE _hb_pg_jobs
311
+ SET job = \( buffer) ,
312
+ lastModified = \( Date . now) ,
313
+ status = \( Status . failed)
314
+ WHERE id = \( id)
315
+ """ ,
316
+ logger: self . logger
317
+ )
318
+ }
298
319
299
320
func delete( jobId: JobID ) async throws {
300
321
try await self . client. query (
@@ -304,7 +325,6 @@ public final class PostgresJobQueue: JobQueueDriver {
304
325
}
305
326
306
327
func addToQueue( jobId: JobID , connection: PostgresConnection , delayUntil: Date ) async throws {
307
- // TODO: assign Date.now in swift-jobs options?
308
328
try await connection. query (
309
329
"""
310
330
INSERT INTO _hb_pg_job_queue (job_id, createdAt, delayed_until)
@@ -316,6 +336,17 @@ public final class PostgresJobQueue: JobQueueDriver {
316
336
)
317
337
}
318
338
339
+ func updateQueue( jobId: JobID , connection: PostgresConnection , delayUntil: Date ) async throws {
340
+ try await connection. query (
341
+ """
342
+ UPDATE _hb_pg_job_queue
343
+ SET delayed_until = \( delayUntil)
344
+ WHERE job_id = \( jobId)
345
+ """ ,
346
+ logger: self . logger
347
+ )
348
+ }
349
+
319
350
func setStatus( jobId: JobID , status: Status , connection: PostgresConnection ) async throws {
320
351
try await connection. query (
321
352
" UPDATE _hb_pg_jobs SET status = \( status) , lastModified = \( Date . now) WHERE id = \( jobId) " ,
0 commit comments