Skip to content

Instantly share code, notes, and snippets.

@momolog
Created September 24, 2015 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save momolog/facf9841a5f14e6f056d to your computer and use it in GitHub Desktop.
Save momolog/facf9841a5f14e6f056d to your computer and use it in GitHub Desktop.
Delayed Job Singleton
module DelayedSingleton
# this first checks whether the same job has already been enqueued.
# if not, it enqueues it to run in one minute
def enqueue_singleton job, at = 1.minute.from_now
unless Delayed::Job.where(:handler => job.to_yaml).any?
Rails.logger.warn "enqueuing singleton job #{job.class.name}"
Delayed::Job.enqueue(job, run_at: at.getutc )
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment