Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# app/worker/cc_enqueuer.rb
class CCEnqueuer
def initialize(delay_time, base_class, options)
@options = options
@delay_time = delay_time
@base_class = base_class
@key = form_key
end
def enqueue_update
return if already_queued?
Delayed::Job.enqueue(self, run_at: @delay_time.from_now)
mark_as_queued
Rails.logger.info { "Enqueued #{enqueuer_name}." }
end
private
def already_queued?
queued = $redis.get(@key)
queued != nil
end
def mark_as_queued
$redis.set(@key, '1')
end
def unmark_as_queued
$redis.del(@key)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment