From eff5108549288b99d1e12840d9efc00457eba6c2 Mon Sep 17 00:00:00 2001 From: "lubomira.trnavska" Date: Sat, 16 Nov 2024 19:35:36 +0100 Subject: [PATCH 1/2] Prevent concurrent draft submit --- app/jobs/govbox/submit_message_draft_job.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/jobs/govbox/submit_message_draft_job.rb b/app/jobs/govbox/submit_message_draft_job.rb index d265b841..0b136a65 100644 --- a/app/jobs/govbox/submit_message_draft_job.rb +++ b/app/jobs/govbox/submit_message_draft_job.rb @@ -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) From 187c4107fbc78a60dcd5e37f213473961a0df622 Mon Sep 17 00:00:00 2001 From: luciajanikova <19lucia99@gmail.com> Date: Mon, 18 Nov 2024 14:39:16 +0100 Subject: [PATCH 2/2] Apply concurrency control on Fs::MessageDrafts submit job too --- app/jobs/fs/submit_message_draft_job.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/jobs/fs/submit_message_draft_job.rb b/app/jobs/fs/submit_message_draft_job.rb index f70e255b..b9070a20 100644 --- a/app/jobs/fs/submit_message_draft_job.rb +++ b/app/jobs/fs/submit_message_draft_job.rb @@ -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)