Class: Cron::TrimFailedDelayedJobs

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

Overview

Automatically update Product Version Lifecycle State to EOL If it is past it’s EOL date Runs Daily

Instance Attribute Summary

Attributes inherited from ApplicationJob

#payload, #started_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TrimCollection

#allowed_time, #allowed_time_for_item, #comparison_field, #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_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

Class Method Details

.valid_environment?Boolean

If the slack API is not present, don’t delete jobs or we wont know about it.

Returns:

  • (Boolean)


36
37
38
# File 'lib/app/jobs/cron/trim_failed_delayed_jobs.rb', line 36

def self.valid_environment?
  SystemConfiguration.slack_api_url.present?
end

Instance Method Details

#archive?(job) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/app/jobs/cron/trim_failed_delayed_jobs.rb', line 14

def archive?(job)
  if 'Delayed::PerformableMethod'.eql?(job.name)

    data = { object: job.failed_object.inspect,
             method: job.failed_method_name,
             args: job.failed_args,
             failed_at: job.failed_at,
             attempts: job.attempts,
             locked_by: job.locked_by }
    SlackNotification.say(data, template: :failed_delayed_job)
    true
  else
    false
  end
rescue StandardError => error
  log_error "Unable to determine if we should archive job: #{job}", error
  false
end

#collectionObject

Return the failed collection



10
11
12
# File 'lib/app/jobs/cron/trim_failed_delayed_jobs.rb', line 10

def collection
  Delayed::Backend::Mongoid::Job.where(:failed_at.exists => true)
end