Class: GoodJob::DiscreteExecution

Inherits:
BaseRecord
  • Object
show all
Includes:
ErrorEvents
Defined in:
app/models/good_job/discrete_execution.rb

Constant Summary

Constants included from ErrorEvents

ErrorEvents::ERROR_EVENTS, ErrorEvents::ERROR_EVENT_ENUMS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ErrorEvents

#error_event, #error_event=

Methods inherited from BaseRecord

bind_value, migrated?, migration_pending_warning!, with_logger_silenced

Class Method Details

.backtrace_migrated?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
# File 'app/models/good_job/discrete_execution.rb', line 24

def self.backtrace_migrated?
  return true if columns_hash["error_backtrace"].present?

  migration_pending_warning!
  false
end

.error_event_migrated?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
# File 'app/models/good_job/discrete_execution.rb', line 17

def self.error_event_migrated?
  return true if columns_hash["error_event"].present?

  migration_pending_warning!
  false
end

Instance Method Details

#display_serialized_paramsObject



63
64
65
66
67
# File 'app/models/good_job/discrete_execution.rb', line 63

def display_serialized_params
  serialized_params.merge({
                            _good_job_execution: attributes.except('serialized_params'),
                          })
end

#filtered_error_backtraceObject



69
70
71
# File 'app/models/good_job/discrete_execution.rb', line 69

def filtered_error_backtrace
  Rails.backtrace_cleaner.clean(error_backtrace || [])
end

#last_status_atObject



45
46
47
# File 'app/models/good_job/discrete_execution.rb', line 45

def last_status_at
  finished_at || created_at
end

#numberObject



31
32
33
# File 'app/models/good_job/discrete_execution.rb', line 31

def number
  serialized_params.fetch('executions', 0) + 1
end

#queue_latencyObject

Time between when this job was expected to run and when it started running



36
37
38
# File 'app/models/good_job/discrete_execution.rb', line 36

def queue_latency
  created_at - scheduled_at
end

#runtime_latencyObject

Time between when this job started and finished



41
42
43
# File 'app/models/good_job/discrete_execution.rb', line 41

def runtime_latency
  (finished_at || Time.current) - performed_at if performed_at
end

#statusObject



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/good_job/discrete_execution.rb', line 49

def status
  if finished_at.present?
    if error.present? && job.finished_at.present?
      :discarded
    elsif error.present?
      :retried
    else
      :succeeded
    end
  else
    :running
  end
end