Skip to content

Instantly share code, notes, and snippets.

@brandonhilkert
Created October 30, 2014 17:49
Show Gist options
  • Select an option

  • Save brandonhilkert/69041c083be4817db761 to your computer and use it in GitHub Desktop.

Select an option

Save brandonhilkert/69041c083be4817db761 to your computer and use it in GitHub Desktop.
unique_worker.rb
UniqueQueueWorker.perform_async(CalendarSyncWorker, "from_google", 1)
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