class Delayed::Plugins::Reporting::Context

Attributes

listener[R]

Public Class Methods

create(reporter: {}, formatter: {}, listener: {}) click to toggle source
# File lib/delayed-plugins-reporting/context.rb, line 26
def create(reporter: {}, formatter: {}, listener: {})
  formatter_options = formatter.dup
  listener_options = listener.dup
  reporter_options = reporter.dup

  formatter_class = formatter_options.delete(:class) || PrettyJsonJobFormatter
  listener_class = listener_options.delete(:class) || JobListener
  reporter_class = reporter_options.delete(:class) || NullReporter

  new(
    listener: listener_class.new(
      reporter: reporter_class.new(
        formatter: formatter_class.new(
          **formatter_options
        ),
        **reporter_options
      ),
      **listener_options
    )
  )
end
new(listener:) click to toggle source
# File lib/delayed-plugins-reporting/context.rb, line 8
def initialize(listener:)
  @listener = listener
end

Public Instance Methods

after_failure(worker, job) click to toggle source
# File lib/delayed-plugins-reporting/context.rb, line 12
def after_failure(worker, job)
  max_attempts = worker.max_attempts(job)

  if max_attempts > 1 && job.attempts == max_attempts
    listener.max_attempts_exceeded(job)
  end
end
before_perform(worker, job) click to toggle source
# File lib/delayed-plugins-reporting/context.rb, line 20
def before_perform(worker, job)
  return if job.attempts.zero?
  listener.job_retried(job)
end