-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FoiAttachmentMaskJob uniqueness methods
Instead of locking jobs to prevent them from running add checks for existing jobs before performing/enqueuing attempting to ensure we execute once only. These methods only work if Sidekiq is used as the ActiveJob adapter.
- Loading branch information
Showing
6 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## | ||
# Module to add methods to check for existing jobs before performing/enqueuing | ||
# attempting to ensure we execute once only. | ||
# | ||
# These methods only work if Sidekiq is used as the ActiveJob adapter. | ||
# | ||
module FoiAttachmentMaskJob::Uniqueness | ||
def self.included(base) | ||
base.extend ClassMethods | ||
end | ||
|
||
module ClassMethods | ||
Check warning on line 12 in app/jobs/foi_attachment_mask_job/uniqueness.rb GitHub Actions / build
|
||
def perform_once_later(attachment) | ||
perform_later(attachment) unless existing_job(attachment) | ||
end | ||
|
||
def perform_once_now(attachment) | ||
existing_job(attachment)&.delete | ||
perform_now(attachment) | ||
end | ||
|
||
def existing_job(attachment) | ||
return unless queue_adapter.is_a?( | ||
ActiveJob::QueueAdapters::SidekiqAdapter | ||
) | ||
|
||
queue = Sidekiq::Queue.new(queue_name) | ||
queue.find do |j| | ||
gid = j.display_args.first['_aj_globalid'] | ||
gid == attachment.to_gid.to_s | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters