Class: Delayed::Plugins::Reporting::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/delayed-plugins-reporting/context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listener:) ⇒ Context

Returns a new instance of Context.



8
9
10
# File 'lib/delayed-plugins-reporting/context.rb', line 8

def initialize(listener:)
  @listener = listener
end

Instance Attribute Details

#listenerObject (readonly)

Returns the value of attribute listener.



6
7
8
# File 'lib/delayed-plugins-reporting/context.rb', line 6

def listener
  @listener
end

Class Method Details

.create(reporter: {}, formatter: {}, listener: {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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

Instance Method Details

#after_failure(worker, job) ⇒ Object



12
13
14
15
16
17
18
# 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) ⇒ Object



20
21
22
23
# File 'lib/delayed-plugins-reporting/context.rb', line 20

def before_perform(worker, job)
  return if job.attempts.zero?
  listener.job_retried(job)
end