Check Existence of DelayedJob Records
I’m using the collectiveidea fork of DelayedJob. There are two ways to create a DelayedJob record. First you can use the delay method.
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
endendSecond way to create DelayedJob records is custom jobs.
#A Custom job is a class with a method called performclass User def perform #long running process endend
#check existence of DelayedJob recordDelayed::Job.exists?(:handler => Delayed::Job.new(:payload_object => User.new).handler, :locked_at => nil)