Class: LogStruct::Log::GoodJob
- Inherits:
-
T::Struct
- Object
- T::Struct
- LogStruct::Log::GoodJob
- Extended by:
- T::Sig
- Includes:
- Interfaces::AdditionalDataField, Interfaces::CommonFields, MergeAdditionalDataFields, SerializeCommon
- Defined in:
- lib/log_struct/log/good_job.rb
Overview
GoodJob log entry for structured logging
GoodJob is a PostgreSQL-based ActiveJob backend that provides reliable, scalable job processing for Rails applications. This log class captures GoodJob-specific events including job execution, database operations, error handling, and performance metrics.
Key Features Logged:
- Job execution lifecycle (enqueue, start, finish, retry)
- Database-backed job persistence events
- Error handling and retry logic
- Job batching and bulk operations
- Performance metrics and timing data
- Thread and process information
Usage Examples:
# Job execution logging
LogStruct::Log::GoodJob.new(
event: Event::Start,
job_id: "job_123",
job_class: "UserNotificationJob",
queue_name: "default",
execution_time: 1.5
)
# Error logging
LogStruct::Log::GoodJob.new(
event: Event::Error,
job_id: "job_123",
error_class: "StandardError",
error_message: "Connection failed"
)
Constant Summary collapse
- GoodJobEvent =
Valid event types for GoodJob operations
T.type_alias { T.any( Event::Log, # General logging Event::Enqueue, # Job queued Event::Start, # Job execution started Event::Finish, # Job completed successfully Event::Error, # Job failed with error Event::Schedule # Job scheduled for future execution ) }
Instance Attribute Summary collapse
-
#additional_data ⇒ Hash{Symbol => T.untyped}
readonly
Additional contextual data.
-
#arguments ⇒ Array<T.untyped>?
readonly
Job execution context.
-
#batch_id ⇒ String?
readonly
Returns the value of prop
batch_id
. -
#cron_key ⇒ String?
readonly
Returns the value of prop
cron_key
. -
#database_connection_name ⇒ String?
readonly
Returns the value of prop
database_connection_name
. -
#error_backtrace ⇒ Array<String>?
readonly
Returns the value of prop
error_backtrace
. -
#error_class ⇒ String?
readonly
Error information.
-
#error_message ⇒ String?
readonly
Returns the value of prop
error_message
. -
#event ⇒ GoodJobEvent
readonly
Returns the value of prop
event
. -
#exception_executions ⇒ Integer?
readonly
Returns the value of prop
exception_executions
. -
#execution_time ⇒ Float?
readonly
Returns the value of prop
execution_time
. -
#executions ⇒ Integer?
readonly
Returns the value of prop
executions
. -
#finished_at ⇒ Time?
readonly
Returns the value of prop
finished_at
. -
#job_class ⇒ String?
readonly
Returns the value of prop
job_class
. -
#job_id ⇒ String?
readonly
Job identification fields.
-
#job_label ⇒ String?
readonly
Returns the value of prop
job_label
. -
#level ⇒ Level
readonly
Returns the value of prop
level
. -
#priority ⇒ Integer?
readonly
Returns the value of prop
priority
. -
#process_id ⇒ Integer?
readonly
GoodJob-specific metadata.
-
#queue_name ⇒ String?
readonly
Returns the value of prop
queue_name
. -
#run_time ⇒ Float?
readonly
Returns the value of prop
run_time
. -
#scheduled_at ⇒ Time?
readonly
Returns the value of prop
scheduled_at
. -
#source ⇒ Source::Job
readonly
Common fields.
-
#thread_id ⇒ String?
readonly
Returns the value of prop
thread_id
. -
#timestamp ⇒ Time
readonly
Returns the value of prop
timestamp
. -
#wait_time ⇒ Float?
readonly
Performance and metrics.
Instance Method Summary collapse
- #initialize(source: T.let(Source::Job, Source::Job), event:, timestamp:, level: T.let(Level::Info, Level), job_id: nil, job_class: nil, queue_name: nil, batch_id: nil, job_label: nil, arguments: nil, executions: nil, exception_executions: nil, execution_time: nil, scheduled_at: nil, error_class: nil, error_message: nil, error_backtrace: nil, process_id: nil, thread_id: nil, priority: nil, cron_key: nil, database_connection_name: nil, wait_time: nil, run_time: nil, finished_at: nil, additional_data: {}) ⇒ void constructor
-
#serialize(strict = true) ⇒ Hash{Symbol => T.untyped}
Convert the log entry to a hash for serialization.
Methods included from MergeAdditionalDataFields
Methods included from SerializeCommon
Constructor Details
#initialize(source: T.let(Source::Job, Source::Job), event:, timestamp:, level: T.let(Level::Info, Level), job_id: nil, job_class: nil, queue_name: nil, batch_id: nil, job_label: nil, arguments: nil, executions: nil, exception_executions: nil, execution_time: nil, scheduled_at: nil, error_class: nil, error_message: nil, error_backtrace: nil, process_id: nil, thread_id: nil, priority: nil, cron_key: nil, database_connection_name: nil, wait_time: nil, run_time: nil, finished_at: nil, additional_data: {}) ⇒ void
|
# File '' const :source, Source::Job, default: T.let(Source::Job, Source::Job) const :event, GoodJobEvent const :timestamp, Time, factory: -> { Time.now } const :level, Level, default: T.let(Level::Info, Level) const :job_id, T.nilable(String), default: nil const :job_class, T.nilable(String), default: nil const :queue_name, T.nilable(String), default: nil const :batch_id, T.nilable(String), default: nil const :job_label, T.nilable(String), default: nil const :arguments, T.nilable(T::Array[T.untyped]), default: nil const :executions, T.nilable(Integer), default: nil const :exception_executions, T.nilable(Integer), default: nil const :execution_time, T.nilable(Float), default: nil const :scheduled_at, T.nilable(Time), default: nil const :error_class, T.nilable(String), default: nil const :error_message, T.nilable(String), default: nil const :error_backtrace, T.nilable(T::Array[String]), default: nil const :process_id, T.nilable(Integer), default: nil const :thread_id, T.nilable(String), default: nil const :priority, T.nilable(Integer), default: nil const :cron_key, T.nilable(String), default: nil const :database_connection_name, T.nilable(String), default: nil const :wait_time, T.nilable(Float), default: nil const :run_time, T.nilable(Float), default: nil const :finished_at, T.nilable(Time), default: nil const :additional_data, T::Hash[Symbol, T.untyped], default: {} |
Instance Attribute Details
#additional_data ⇒ Hash{Symbol => T.untyped} (readonly)
Additional contextual data
|
# File '' const :additional_data, T::Hash[Symbol, T.untyped], default: {} |
#arguments ⇒ Array<T.untyped>? (readonly)
Job execution context
|
# File '' const :arguments, T.nilable(T::Array[T.untyped]), default: nil |
#batch_id ⇒ String? (readonly)
Returns the value of prop batch_id
.
|
# File '' const :batch_id, T.nilable(String), default: nil |
#cron_key ⇒ String? (readonly)
Returns the value of prop cron_key
.
|
# File '' const :cron_key, T.nilable(String), default: nil |
#database_connection_name ⇒ String? (readonly)
Returns the value of prop database_connection_name
.
|
# File '' const :database_connection_name, T.nilable(String), default: nil |
#error_backtrace ⇒ Array<String>? (readonly)
Returns the value of prop error_backtrace
.
|
# File '' const :error_backtrace, T.nilable(T::Array[String]), default: nil |
#error_class ⇒ String? (readonly)
Error information
|
# File '' const :error_class, T.nilable(String), default: nil |
#error_message ⇒ String? (readonly)
Returns the value of prop error_message
.
|
# File '' const :error_message, T.nilable(String), default: nil |
#event ⇒ GoodJobEvent (readonly)
Returns the value of prop event
.
|
# File '' const :event, GoodJobEvent |
#exception_executions ⇒ Integer? (readonly)
Returns the value of prop exception_executions
.
|
# File '' const :exception_executions, T.nilable(Integer), default: nil |
#execution_time ⇒ Float? (readonly)
Returns the value of prop execution_time
.
|
# File '' const :execution_time, T.nilable(Float), default: nil |
#executions ⇒ Integer? (readonly)
Returns the value of prop executions
.
|
# File '' const :executions, T.nilable(Integer), default: nil |
#finished_at ⇒ Time? (readonly)
Returns the value of prop finished_at
.
|
# File '' const :finished_at, T.nilable(Time), default: nil |
#job_class ⇒ String? (readonly)
Returns the value of prop job_class
.
|
# File '' const :job_class, T.nilable(String), default: nil |
#job_id ⇒ String? (readonly)
Job identification fields
|
# File '' const :job_id, T.nilable(String), default: nil |
#job_label ⇒ String? (readonly)
Returns the value of prop job_label
.
|
# File '' const :job_label, T.nilable(String), default: nil |
#level ⇒ Level (readonly)
Returns the value of prop level
.
|
# File '' const :level, Level, default: T.let(Level::Info, Level) |
#priority ⇒ Integer? (readonly)
Returns the value of prop priority
.
|
# File '' const :priority, T.nilable(Integer), default: nil |
#process_id ⇒ Integer? (readonly)
GoodJob-specific metadata
|
# File '' const :process_id, T.nilable(Integer), default: nil |
#queue_name ⇒ String? (readonly)
Returns the value of prop queue_name
.
|
# File '' const :queue_name, T.nilable(String), default: nil |
#run_time ⇒ Float? (readonly)
Returns the value of prop run_time
.
|
# File '' const :run_time, T.nilable(Float), default: nil |
#scheduled_at ⇒ Time? (readonly)
Returns the value of prop scheduled_at
.
|
# File '' const :scheduled_at, T.nilable(Time), default: nil |
#source ⇒ Source::Job (readonly)
Common fields
|
# File '' const :source, Source::Job, default: T.let(Source::Job, Source::Job) |
#thread_id ⇒ String? (readonly)
Returns the value of prop thread_id
.
|
# File '' const :thread_id, T.nilable(String), default: nil |
#timestamp ⇒ Time (readonly)
Returns the value of prop timestamp
.
|
# File '' const :timestamp, Time, factory: -> { Time.now } |
#wait_time ⇒ Float? (readonly)
Performance and metrics
|
# File '' const :wait_time, T.nilable(Float), default: nil |
Instance Method Details
#serialize(strict = true) ⇒ Hash{Symbol => T.untyped}
Convert the log entry to a hash for serialization
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/log_struct/log/good_job.rb', line 112 def serialize(strict = true) hash = serialize_common(strict) merge_additional_data_fields(hash) # Add job identification fields hash[LOG_KEYS.fetch(:job_id)] = job_id if job_id hash[LOG_KEYS.fetch(:job_class)] = job_class if job_class hash[LOG_KEYS.fetch(:queue_name)] = queue_name if queue_name hash[:batch_id] = batch_id if batch_id hash[:job_label] = job_label if job_label # Add execution context hash[LOG_KEYS.fetch(:arguments)] = arguments if arguments hash[:executions] = executions if executions hash[:exception_executions] = exception_executions if exception_executions hash[:execution_time] = execution_time if execution_time hash[:scheduled_at] = scheduled_at&.iso8601 if scheduled_at # Add error information hash[LOG_KEYS.fetch(:err_class)] = error_class if error_class hash[:error_message] = if hash[LOG_KEYS.fetch(:backtrace)] = error_backtrace if error_backtrace # Add GoodJob-specific metadata hash[LOG_KEYS.fetch(:process_id)] = process_id if process_id hash[LOG_KEYS.fetch(:thread_id)] = thread_id if thread_id hash[:priority] = priority if priority hash[:cron_key] = cron_key if cron_key hash[:database_connection_name] = database_connection_name if database_connection_name # Add performance metrics hash[:wait_time] = wait_time if wait_time hash[:run_time] = run_time if run_time hash[:finished_at] = finished_at&.iso8601 if finished_at hash end |