Class: Workhorse::Jobs::CleanupSucceededJobs

Inherits:
Object
  • Object
show all
Defined in:
lib/workhorse/jobs/cleanup_succeeded_jobs.rb

Instance Method Summary collapse

Constructor Details

#initialize(max_age: 14) ⇒ CleanupSucceededJobs

Instantiates a new job.

Parameters:

  • max_age (Integer) (defaults to: 14)

    The maximal age of jobs to retain, in days. Will be evaluated at perform time.



7
8
9
# File 'lib/workhorse/jobs/cleanup_succeeded_jobs.rb', line 7

def initialize(max_age: 14)
  @max_age = max_age
end

Instance Method Details

#performObject



11
12
13
14
15
16
# File 'lib/workhorse/jobs/cleanup_succeeded_jobs.rb', line 11

def perform
  age_limit = seconds_ago(@max_age)
  Workhorse::DbJob.where(
    'STATE = ? AND UPDATED_AT <= ?', Workhorse::DbJob::STATE_SUCCEEDED, age_limit
  ).delete_all
end