ruby on rails - specifying different retry limit and retry delay for different jobs in backburner -


i using beaneater/beanstalk in app maintaining job queues. https://github.com/nesquena/backburner

my global config file backburner -

backburner.configure |config|   config.beanstalk_url    = ["beanstalk://#{config['beanstalk']['host']}:#{config['beanstalk']['port']}"]   config.tube_namespace   = config['beanstalk']['tube_name']   config.on_error         = lambda { |e| puts e }   config.max_job_retries  = 5 # default 0 retries   config.retry_delay      = 30 # default 5 seconds   config.default_priority = 65536   config.respond_timeout  = 120   config.default_worker   = backburner::workers::simple   config.logger           = logger.new('log/backburner.log')   config.priority_labels  = { :custom => 50, :useless => 1000 }   config.reserve_timeout  = nil end 

i want set different retry limit , retry delay different jobs. looking @ rubydoc corresponding variable/function. as per rubydoc link, tried configuring retry_limit locally in worker as:

one specific worker -

class abcjob   include backburner::queue   queue "abc_job"  # defaults 'backburner-jobs' tube   queue_priority 10 # urgent priority 0   queue_respond_timeout 300 # number of seconds before job times out   queue_retry_limit 2    def self.perform(abc_id)     .....task done.....   end end 

however, still picking retry limit global config file , retrying 5 times instead of 2. thing missing here?

how can on write retry limit , retry delay locally?

i not find right way found solution. putting entire body of perform in begin-rescue block , in case of failure re-enqueing custom delay. also, keep track of number of retries made argument enqueueing.

class abcjob include backburner::queue queue "abc_job"  # defaults 'backburner-jobs' tube queue_priority 10 # urgent priority 0 queue_respond_timeout 300 # number of seconds before job times out  def self.perform(abc_id, attempt = 1)   begin     .....task done.....   rescue standarderror => e     # notification method can know failure reason , fix before next retry     # using notificationmailer e.message body debug     # function want retry delay be, using quadratic     delay = attempt * attempt     if attempt + 1 < globalconstant::maxretrycount       backburner::worker.enqueue(abcjob, [abc_id, attempt + 1], delay: delay.minute)     else       raise # if want jobs buried     end   end end 

i have kept default value of attempt 1 magic nuber 1 not appear in code might raise question why passing constant. enqueueing other places in code can use simple enqueue

backburner::worker.enqueue(abcjob, abc_id) 

Comments

Post a Comment

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -