Created
October 30, 2014 17:49
-
-
Save brandonhilkert/69041c083be4817db761 to your computer and use it in GitHub Desktop.
unique_worker.rb
This file contains hidden or 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
| UniqueQueueWorker.perform_async(CalendarSyncWorker, "from_google", 1) |
This file contains hidden or 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
| require 'sidekiq/api' | |
| class UniqueQueueWorker | |
| def initialize(processor, *args) | |
| @processor, @args = processor, args | |
| end | |
| def exists? | |
| Sidekiq::Queue.new.any? { |job| job.klass == processor.to_s && job.args == args } | |
| end | |
| def enqueue | |
| processor.send(:perform_async, *args) | |
| end | |
| def self.perform_async(processor, *args) | |
| q = new(processor, *args) | |
| q.enqueue unless q.exists? | |
| end | |
| private | |
| attr_reader :processor, :args | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment