Class: Signalman::JobHandler

Inherits:
BaseHandler show all
Defined in:
lib/signalman.rb

Instance Attribute Summary

Attributes inherited from BaseHandler

#current_time, #event

Instance Method Summary collapse

Methods inherited from BaseHandler

call, #create_event, #finished_at, #initialize, #skip?, #start, #started_at

Constructor Details

This class inherits a constructor from Signalman::BaseHandler

Instance Method Details

#args_info(job) ⇒ Object



134
135
136
137
138
139
140
141
# File 'lib/signalman.rb', line 134

def args_info(job)
  if job.class.log_arguments? && job.arguments.any?
    " with arguments: " +
      job.arguments.map { |arg| format(arg).inspect }.join(", ")
  else
    ""
  end
end

#format(arg) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/signalman.rb', line 143

def format(arg)
  case arg
  when Hash
    arg.transform_values { |value| format(value) }
  when Array
    arg.map { |value| format(value) }
  when GlobalID::Identification
    arg.to_global_id rescue arg
  else
    arg
  end
end

#processObject



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/signalman.rb', line 116

def process
  job = event.payload[:job]
  create_event(
    class: job.class.name,
    id: job.job_id,
    enqueued_at: job.enqueued_at,
    scheduled_at: scheduled_at(event),
    queue_name: queue_name(event),
    args: args_info(job)
  )
end

#queue_name(event) ⇒ Object

From ActiveJob::LogSubscriber



129
130
131
132
# File 'lib/signalman.rb', line 129

def queue_name(event)
  # Rails 7.1 -> ActiveJob.adapter_name(event.payload[:adapter]) + "(#{event.payload[:job].queue_name})"
  event.payload[:adapter].class.name.demodulize.remove("Adapter") + "(#{event.payload[:job].queue_name})"
end

#scheduled_at(event) ⇒ Object



156
157
158
159
# File 'lib/signalman.rb', line 156

def scheduled_at(event)
  return unless event.payload[:job].scheduled_at
  Time.at(event.payload[:job].scheduled_at).utc
end