Created
August 29, 2011 00:07
-
-
Save emrekutlu/1177431 to your computer and use it in GitHub Desktop.
Check existence of DelayedJob records
This file contains 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
#A Custom job is a class with a method called perform | |
class User | |
def perform | |
#long running process | |
end | |
end | |
#check existence of DelayedJob record | |
Delayed::Job.exists?(:handler => Delayed::Job.new(:payload_object => User.new).handler, :locked_at => nil) | |
This file contains 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
class User | |
class << self | |
def long_process(args) | |
#long running process | |
end | |
def create_delayed_job_for_long_process(args) | |
#check the existence of DelayedJob record | |
unless Delayed::Job.exists?(:handler => Delayed::Job.new(:payload_object => Delayed::PerformableMethod.new(self, :request_without_send_later, Array.wrap(args))).handler, :locked_at => nil) | |
self.delay.long_process(args) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment