Home > Blockchain >  Is there a way to, not delete a job for specific queue even delete_failed_jobs: true globally?
Is there a way to, not delete a job for specific queue even delete_failed_jobs: true globally?

Time:07-18

class User < ApplicationRecord
  def update_avatar
     #some avatar image processing
  end
  handle_asynchronously :update_avatar, queue: :image_processing
end

I'm using gem delayed_job_active_record with default config for failed jobs as delete_failed_jobs: true. I would like to not delete jobs on queue image_processing, How can I achieve the case.

CodePudding user response:

As described here, to set a per-job default for destroying failed jobs that overrides the Delayed::Worker.destroy_failed_jobs you can define a destroy_failed_jobs? method on the job

NewsletterJob = Struct.new(:text, :emails) do
  def perform
    emails.each { |e| NewsletterMailer.deliver_text_to_email(text, e) }
  end

  def destroy_failed_jobs?
    false
  end
end

in your case something similar to this:

class YourJob
  ...
  def destroy_failed_jobs?
    queue_name != 'image_processing'
  end
end
  • Related