Skip to content

Instantly share code, notes, and snippets.

@emrekutlu
Created August 29, 2011 00:07
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 emrekutlu/1177431 to your computer and use it in GitHub Desktop.
Save emrekutlu/1177431 to your computer and use it in GitHub Desktop.
Check existence of DelayedJob records
#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)
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