Class: LogStruct::Integrations::GoodJob::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/log_struct/integrations/good_job/log_subscriber.rb

Overview

LogSubscriber for GoodJob ActiveSupport notifications

This subscriber captures GoodJob's ActiveSupport notifications and converts them into structured LogStruct::Log::GoodJob entries. It provides detailed logging for job lifecycle events, performance metrics, and error tracking.

Supported Events:

  • job.enqueue - Job queued for execution
  • job.start - Job execution started
  • job.finish - Job completed successfully
  • job.error - Job failed with error
  • job.retry - Job retry initiated
  • job.schedule - Job scheduled for future execution

Event Data Captured:

  • Job identification (ID, class, queue)
  • Execution context (arguments, priority, scheduled time)
  • Performance metrics (execution time, wait time)
  • Error information (class, message, backtrace)
  • Process and thread information

Instance Method Summary collapse

Instance Method Details

#enqueue(event) ⇒ void

This method returns an undefined value.

Job enqueued event

Parameters:

  • event (T.untyped)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/log_struct/integrations/good_job/log_subscriber.rb', line 42

def enqueue(event)
  job_data = extract_job_data(event)

  log_entry = LogStruct::Log::GoodJob.new(
    event: Event::Enqueue,
    level: Level::Info,
    job_id: job_data[:job_id],
    job_class: job_data[:job_class],
    queue_name: job_data[:queue_name],
    arguments: job_data[:arguments],
    scheduled_at: job_data[:scheduled_at],
    priority: job_data[:priority],
    execution_time: event.duration,
    additional_data: {
      enqueue_caller: job_data[:caller_location]
    }
  )

  logger.info(log_entry)
end

#error(event) ⇒ void

This method returns an undefined value.

Job failed with error event

Parameters:

  • event (T.untyped)


111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/log_struct/integrations/good_job/log_subscriber.rb', line 111

def error(event)
  job_data = extract_job_data(event)

  log_entry = LogStruct::Log::GoodJob.new(
    event: Event::Error,
    level: Level::Error,
    job_id: job_data[:job_id],
    job_class: job_data[:job_class],
    queue_name: job_data[:queue_name],
    executions: job_data[:executions],
    exception_executions: job_data[:exception_executions],
    error_class: job_data[:error_class],
    error_message: job_data[:error_message],
    error_backtrace: job_data[:error_backtrace],
    run_time: event.duration,
    process_id: ::Process.pid,
    thread_id: Thread.current.object_id.to_s(36)
  )

  logger.error(log_entry)
end

#finish(event) ⇒ void

This method returns an undefined value.

Job completed successfully event

Parameters:

  • event (T.untyped)


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/log_struct/integrations/good_job/log_subscriber.rb', line 87

def finish(event)
  job_data = extract_job_data(event)

  log_entry = LogStruct::Log::GoodJob.new(
    event: Event::Finish,
    level: Level::Info,
    job_id: job_data[:job_id],
    job_class: job_data[:job_class],
    queue_name: job_data[:queue_name],
    executions: job_data[:executions],
    run_time: event.duration,
    finished_at: Time.now,
    process_id: ::Process.pid,
    thread_id: Thread.current.object_id.to_s(36),
    additional_data: {
      result: job_data[:result]
    }
  )

  logger.info(log_entry)
end

#schedule(event) ⇒ void

This method returns an undefined value.

Job scheduled for future execution event

Parameters:

  • event (T.untyped)


135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/log_struct/integrations/good_job/log_subscriber.rb', line 135

def schedule(event)
  job_data = extract_job_data(event)

  log_entry = LogStruct::Log::GoodJob.new(
    event: Event::Schedule,
    level: Level::Info,
    job_id: job_data[:job_id],
    job_class: job_data[:job_class],
    queue_name: job_data[:queue_name],
    arguments: job_data[:arguments],
    scheduled_at: job_data[:scheduled_at],
    priority: job_data[:priority],
    cron_key: job_data[:cron_key],
    execution_time: event.duration
  )

  logger.info(log_entry)
end

#start(event) ⇒ void

This method returns an undefined value.

Job execution started event

Parameters:

  • event (T.untyped)


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/log_struct/integrations/good_job/log_subscriber.rb', line 65

def start(event)
  job_data = extract_job_data(event)

  log_entry = LogStruct::Log::GoodJob.new(
    event: Event::Start,
    level: Level::Info,
    job_id: job_data[:job_id],
    job_class: job_data[:job_class],
    queue_name: job_data[:queue_name],
    arguments: job_data[:arguments],
    executions: job_data[:executions],
    wait_time: job_data[:wait_time],
    scheduled_at: job_data[:scheduled_at],
    process_id: ::Process.pid,
    thread_id: Thread.current.object_id.to_s(36)
  )

  logger.info(log_entry)
end