Module: GoodJob::ErrorEvents

Extended by:
ActiveSupport::Concern
Included in:
BaseExecution, DiscreteExecution
Defined in:
app/models/concerns/good_job/error_events.rb

Overview

Shared methods for filtering Execution/Job records from the good_jobs table.

Constant Summary collapse

ERROR_EVENTS =
[
  ERROR_EVENT_INTERRUPTED = 'interrupted',
  ERROR_EVENT_UNHANDLED = 'unhandled',
  ERROR_EVENT_HANDLED = 'handled',
  ERROR_EVENT_RETRIED = 'retried',
  ERROR_EVENT_RETRY_STOPPED = 'retry_stopped',
  ERROR_EVENT_DISCARDED = 'discarded',
].freeze
ERROR_EVENT_ENUMS =
{
  ERROR_EVENT_INTERRUPTED => 0,
  ERROR_EVENT_UNHANDLED => 1,
  ERROR_EVENT_HANDLED => 2,
  ERROR_EVENT_RETRIED => 3,
  ERROR_EVENT_RETRY_STOPPED => 4,
  ERROR_EVENT_DISCARDED => 5,
}.freeze

Instance Method Summary collapse

Instance Method Details

#error_eventObject

TODO: GoodJob v4 can make this an ‘enum` once migrations are guaranteed.



27
28
29
30
31
32
33
34
# File 'app/models/concerns/good_job/error_events.rb', line 27

def error_event
  return unless self.class.columns_hash['error_event']

  enum = read_attribute(:error_event)
  return unless enum

  ERROR_EVENT_ENUMS.key(enum)
end

#error_event=(event) ⇒ Object

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
43
# File 'app/models/concerns/good_job/error_events.rb', line 36

def error_event=(event)
  return unless self.class.columns_hash['error_event']

  enum = ERROR_EVENT_ENUMS[event]
  raise(ArgumentError, "Invalid error_event: #{event}") if event && !enum

  write_attribute(:error_event, enum)
end