Skip to content

Commit

Permalink
Fix DatabaseQueue deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuawright11 committed Oct 1, 2021
1 parent dd95663 commit c64f073
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/Alchemy/Queue/Drivers/DatabaseQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class DatabaseQueue: QueueDriver {
.forLock(.update, option: .skipLocked)
.firstModel()

return try await job?.update {
return try await job?.update(db: conn) {
$0.reserved = true
$0.reservedAt = Date()
}.toJobData()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Alchemy/Queue/Drivers/QueueDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extension QueueDriver {
return
}

Log.debug("Dequeued job \(jobData.jobName) from queue \(jobData.channel)")
Log.debug("[Queue] dequeued job \(jobData.jobName) from queue \(jobData.channel)")
try await execute(jobData)
try await runNext(from: channels)
} catch {
Expand Down
2 changes: 2 additions & 0 deletions Sources/Alchemy/Queue/Queue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public final class Queue: Service {
pollRate: TimeAmount = Queue.defaultPollRate,
on eventLoop: EventLoop = Loop.group.next()
) {
let loopId = ObjectIdentifier(eventLoop).debugDescription.dropLast().suffix(6)
Log.info("[Queue] starting worker \(loopId)")
driver.startWorker(for: channels, pollRate: pollRate, on: eventLoop)
}
}
Expand Down

0 comments on commit c64f073

Please sign in to comment.