Skip to content

Commit f302c45

Browse files
authored
Fix SQLite with delayed jobs (#16)
Currently, jobs with a value for `delay_until` are never run when using SQLite as the underlying database. This is because one of the conditions used to select a job is `unixepoch(coalesce("delay_until", 'now')) <= unixepoch('now')`. This is fine if `delay_until` is NULL, since it will be equivalent to `unixepoch('now') <= unixepoch('now')` which is always true. However, if `delay_until` has a value, the condition becomes equivalent to `unixepoch("delay_until") <= unixepoch('now')` which is incorrect since `delay_until` is already stored as an epoch timestamp. Passing a epoch timestamp to `unixepoch` results in NULL.
1 parent 20ebbf1 commit f302c45

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Sources/QueuesFluentDriver/FluentQueue.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public struct FluentQueue: AsyncQueue, Sendable {
9999
.from(self.jobsTable)
100100
.where("state", .equal, .literal(StoredJobState.pending))
101101
.where("queue_name", .equal, self.queueName)
102-
.where(.dateValue(.function("coalesce", .column("delay_until"), SQLNow())), .lessThanOrEqual, .now())
102+
.where(.function("coalesce", .column("delay_until"), .now()), .lessThanOrEqual, .now())
103103
.orderBy("delay_until")
104104
.orderBy("queued_at")
105105
.limit(1)

0 commit comments

Comments
 (0)