Skip to content

Commit 09328ae

Browse files
committed
Update addToQueue to remove non optional delayUntil
* Update addToQueue to drop optional value for delayUntil since it's no longer optional upstream * Use JobQueueError for decoding failure
1 parent c9c6212 commit 09328ae

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ let package = Package(
99
.library(name: "JobsPostgres", targets: ["JobsPostgres"])
1010
],
1111
dependencies: [
12-
.package(url: "https://github.com/hummingbird-project/swift-jobs.git", from: "1.0.0-beta.7"),
12+
// TODO: use a released version of swift-jobs
13+
.package(url: "https://github.com/hummingbird-project/swift-jobs.git", branch: "main"),
1314
.package(url: "https://github.com/hummingbird-project/hummingbird-postgres.git", from: "0.5.0"),
1415
.package(url: "https://github.com/vapor/postgres-nio.git", from: "1.25.0"),
1516
],

Sources/JobsPostgres/PostgresJobsQueue.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,13 @@ public final class PostgresJobQueue: JobQueueDriver {
235235
return Result.success(QueuedJob(id: jobId, jobBuffer: buffer))
236236
} catch {
237237
try await self.setStatus(jobId: jobId, status: .failed, connection: connection)
238-
return Result.failure(JobQueueError.decodeJobFailed)
238+
return Result.failure(
239+
JobQueueError(
240+
code: .decodeJobFailed,
241+
jobName: nil,
242+
details: "\(String(reflecting: error))"
243+
)
244+
)
239245
}
240246
}
241247
}
@@ -276,12 +282,12 @@ public final class PostgresJobQueue: JobQueueDriver {
276282
)
277283
}
278284

279-
func addToQueue(jobId: JobID, connection: PostgresConnection, delayUntil: Date?) async throws {
285+
func addToQueue(jobId: JobID, connection: PostgresConnection, delayUntil: Date) async throws {
280286
// TODO: assign Date.now in swift-jobs options?
281287
try await connection.query(
282288
"""
283289
INSERT INTO _hb_pg_job_queue (job_id, createdAt, delayed_until)
284-
VALUES (\(jobId), \(Date.now), \(delayUntil ?? Date.now))
290+
VALUES (\(jobId), \(Date.now), \(delayUntil))
285291
-- We have found an existing job with the same id, SKIP this INSERT
286292
ON CONFLICT (job_id) DO NOTHING
287293
""",
@@ -327,7 +333,7 @@ public final class PostgresJobQueue: JobQueueDriver {
327333
let jobs = try await getJobs(withStatus: status)
328334
self.logger.info("Moving \(jobs.count) jobs with status: \(status) to job queue")
329335
for jobId in jobs {
330-
try await self.addToQueue(jobId: jobId, connection: connection, delayUntil: nil)
336+
try await self.addToQueue(jobId: jobId, connection: connection, delayUntil: Date.now)
331337
}
332338

333339
case .doNothing:

0 commit comments

Comments
 (0)