class RocketJob::Jobs::HousekeepingJob
Applies Retention policies to how long jobs are kept.
Retentions are specific to each state so that for example completed jobs can be cleaned up before jobs that are running.
Only one active instance of this housekeeping job is permitted at a time.
Example:
RocketJob::Jobs::HousekeepingJob.create!
Example, with the default values that can be modified:
RocketJob::Jobs::HousekeepingJob.create!( aborted_retention: 7.days, completed_retention: 7.days, failed_retention: 14.days, paused_retention: nil, queued_retention: nil )
Example, overriding defaults and disabling removal of failed jobs:
RocketJob::Jobs::HousekeepingJob.create!( aborted_retention: 1.day, completed_retention: 30.minutes, failed_retention: nil )
Public Instance Methods
perform()
click to toggle source
# File lib/rocket_job/jobs/housekeeping_job.rb, line 47 def perform RocketJob::Job.aborted.where(completed_at: {"$lte" => aborted_retention.seconds.ago}).destroy_all if aborted_retention if completed_retention RocketJob::Job.completed.where(completed_at: {"$lte" => completed_retention.seconds.ago}).destroy_all end RocketJob::Job.failed.where(completed_at: {"$lte" => failed_retention.seconds.ago}).destroy_all if failed_retention RocketJob::Job.paused.where(completed_at: {"$lte" => paused_retention.seconds.ago}).destroy_all if paused_retention RocketJob::Job.queued.where(created_at: {"$lte" => queued_retention.seconds.ago}).destroy_all if queued_retention return unless destroy_zombies # Cleanup zombie servers RocketJob::Server.destroy_zombies # Requeue jobs where the worker is in the zombie state and its server has gone away RocketJob::ActiveWorker.requeue_zombies end