Class: Cron::TrimDelayedJobWorkers

Inherits:
TrimCollection show all
Defined in:
lib/app/jobs/cron/trim_delayed_job_workers.rb

Overview

Clean up Audit Logs that have not been updated in 90 days

Instance Attribute Summary

Attributes inherited from ApplicationJob

#payload, #started_at

Instance Method Summary collapse

Methods inherited from TrimCollection

#allowed_time_for_item, #execute, #trim_item

Methods inherited from Job

cron_tab_entry, #notify_job_failure, #send_support_email

Methods inherited from ApplicationJob

#duration, #parse_payload, #perform, valid_environment?, valid_environments

Methods included from App47Logger

clean_params, #clean_params, delete_parameter_keys, #log_controller_error, log_debug, #log_debug, log_error, #log_error, log_exception, #log_message, log_message, #log_warn, log_warn, mask_parameter_keys, #update_flash_messages

Instance Method Details

#allowed_timeObject

Allowed time the amount of time allowed to exists before deleting



35
36
37
# File 'lib/app/jobs/cron/trim_delayed_job_workers.rb', line 35

def allowed_time
  2.days.ago.utc
end

#archive?(worker) ⇒ Boolean

Check if the cron job server hasn’t reported in a while

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'lib/app/jobs/cron/trim_delayed_job_workers.rb', line 18

def archive?(worker)
  super && worker.runs.blank?
rescue StandardError => error
  App47Logger.log_warn "Unable to archive item #{worker.inspect}", error
  false
end

#collectionObject

Fetch each Audit Log and delete it if hasn’t been updated in 90 days



11
12
13
# File 'lib/app/jobs/cron/trim_delayed_job_workers.rb', line 11

def collection
  Delayed::Jobs::Worker.all
end

#comparison_fieldObject

Return which field to use for comparison when trimming objects



28
29
30
# File 'lib/app/jobs/cron/trim_delayed_job_workers.rb', line 28

def comparison_field
  :last_check_in_at
end