Skip to content

Commit

Permalink
Add an "initial" state to jobs to avoid race conditions between the s…
Browse files Browse the repository at this point in the history
…et() and push() queue operations. Fixes #13
  • Loading branch information
gwynne committed Oct 24, 2024
1 parent 4e31dfa commit d2388b1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/QueuesFluentDriver/FluentQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public struct FluentQueue: AsyncQueue, Sendable {
.bind(jobStorage.jobName),
.bind(jobStorage.queuedAt),
.bind(jobStorage.delayUntil),
.literal(StoredJobState.pending),
.literal(StoredJobState.initial),
.bind(jobStorage.maxRetryCount),
.bind(jobStorage.attempts),
.bind(Data(jobStorage.payload)),
Expand Down
3 changes: 3 additions & 0 deletions Sources/QueuesFluentDriver/JobModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import struct Queues.QueueName

/// The state of a job currently stored in the database.
enum StoredJobState: String, Codable, CaseIterable {
/// Job has been set up but is not yet ready to execute.
case initial

/// Job is ready to be picked up for execution.
case pending

Expand Down

0 comments on commit d2388b1

Please sign in to comment.