Created
September 24, 2015 13:36
-
-
Save momolog/facf9841a5f14e6f056d to your computer and use it in GitHub Desktop.
Delayed Job Singleton
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
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