Class: LogStasher::ActiveJob::LogSubscriber

Inherits:
BASE_SUBSCRIBER
  • Object
show all
Defined in:
lib/logstasher/active_job/log_subscriber.rb

Instance Method Summary collapse

Instance Method Details

#enqueue(event) ⇒ Object



19
20
21
# File 'lib/logstasher/active_job/log_subscriber.rb', line 19

def enqueue(event)
  process_event(event, 'enqueue')
end

#enqueue_at(event) ⇒ Object



23
24
25
# File 'lib/logstasher/active_job/log_subscriber.rb', line 23

def enqueue_at(event)
  process_event(event, 'enqueue_at')
end

#loggerObject



50
51
52
# File 'lib/logstasher/active_job/log_subscriber.rb', line 50

def logger
  LogStasher.logger
end

#perform(event) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/logstasher/active_job/log_subscriber.rb', line 27

def perform(event)
  process_event(event, 'perform')

  # Revert the request id back, in the event that the inline adapter is being used or a
  # perform_now was used.
  LogStasher.request_context[:request_id] = Thread.current[:old_request_id]
  Thread.current[:old_request_id] = nil
end

#perform_start(event) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/logstasher/active_job/log_subscriber.rb', line 36

def perform_start(event)
  # Use the job_id as the request id, so that any custom logging done for a job
  # shares a request id, and has the job id in each log line.
  #
  # It's not being set when the job is enqueued, so enqueuing a job will have it's default
  # request_id. In a lot of cases, it will be because of a web request.
  #
  # Hang onto the old request id, so we can revert after the job is done being performed.
  Thread.current[:old_request_id] = LogStasher.request_context[:request_id]
  LogStasher.request_context[:request_id] = event.payload[:job].job_id

  process_event(event, 'perform_start')
end