Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent concurrent draft submit #508

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/jobs/fs/submit_message_draft_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
class Fs::SubmitMessageDraftJob < ApplicationJob
include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
# Maximum number of unfinished jobs to allow with the concurrency key
# Can be an Integer or Lambda/Proc that is invoked in the context of the job
total_limit: 1,

key: -> { "Fs::SubmitMessageDraftJob-#{arguments.first.try(:id)}" }
)

def perform(message_draft, bulk_submit: false, fs_client: FsEnvironment.fs_client)
raise "Invalid message!" unless message_draft.valid?(:validate_data)

Expand Down
10 changes: 10 additions & 0 deletions app/jobs/govbox/submit_message_draft_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ class SubmissionError < StandardError
class TemporarySubmissionError < SubmissionError
end

include GoodJob::ActiveJobExtensions::Concurrency

good_job_control_concurrency_with(
# Maximum number of unfinished jobs to allow with the concurrency key
# Can be an Integer or Lambda/Proc that is invoked in the context of the job
total_limit: 1,

key: -> { "Govbox::SubmitMessageDraftJob-#{arguments.first.try(:id)}" }
)

retry_on TemporarySubmissionError, wait: 2.minutes, attempts: 5

def perform(message_draft, bulk_submit: false, upvs_client: UpvsEnvironment.upvs_client)
Expand Down
Loading