Class: GoodJob::LogSubscriber
- Inherits:
-
ActiveSupport::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- GoodJob::LogSubscriber
- Defined in:
- lib/good_job/log_subscriber.rb
Overview
Listens to GoodJob notifications and logs them.
Each method corresponds to the name of a notification. For example, when the Scheduler shuts down, it sends a notification named “scheduler_shutdown.good_job” and the #scheduler_shutdown method will be called here. See the ActiveSupport::LogSubscriber documentation for more.
Notifications collapse
-
#cleanup_preserved_jobs(event) ⇒ void
Responds to the
cleanup_preserved_jobs.good_job
notification. -
#create(event) ⇒ void
Responds to the
create.good_job
notification. -
#cron_manager_start(event) ⇒ void
Responds to the
cron_manager_start.good_job
notification. -
#finished_job_task(event) ⇒ void
Responds to the
finished_job_task.good_job
notification. -
#finished_timer_task(event) ⇒ void
Responds to the
finished_timer_task.good_job
notification. -
#notifier_listen(event) ⇒ void
Responds to the
notifier_listen.good_job
notification. -
#notifier_notified(event) ⇒ void
Responds to the
notifier_notified.good_job
notification. -
#notifier_notify_error(event) ⇒ void
Responds to the
notifier_notify_error.good_job
notification. -
#notifier_unlisten(event) ⇒ void
Responds to the
notifier_unlisten.good_job
notification. -
#perform_job(event) ⇒ void
Responds to the
perform_job.good_job
notification. -
#scheduler_create_pool(event) ⇒ void
Responds to the
scheduler_create_pool.good_job
notification. -
#scheduler_restart_pools(event) ⇒ void
Responds to the
scheduler_restart_pools.good_job
notification. -
#scheduler_shutdown(event) ⇒ void
Responds to the
scheduler_shutdown.good_job
notification. -
#scheduler_shutdown_start(event) ⇒ void
Responds to the
scheduler_shutdown_start.good_job
notification.
Class Method Summary collapse
-
.logger ⇒ Logger
Represents all the loggers attached to LogSubscriber with a single logging interface.
-
.loggers ⇒ Array<Logger>
Tracks all loggers that LogSubscriber is writing to.
-
.reset_logger ⇒ void
Reset LogSubscriber.logger and force it to rebuild a new shortcut to all the loggers in LogSubscriber.loggers.
Instance Method Summary collapse
-
#logger ⇒ Logger
Get the logger associated with this LogSubscriber instance.
Class Method Details
.logger ⇒ Logger
Represents all the loggers attached to GoodJob::LogSubscriber with a single logging interface. Writing to this logger is a shortcut for writing to each of the loggers in loggers.
178 179 180 181 182 183 184 185 186 |
# File 'lib/good_job/log_subscriber.rb', line 178 def logger @_logger ||= begin logger = Logger.new(StringIO.new) loggers.each do |each_logger| logger.extend(ActiveSupport::Logger.broadcast(each_logger)) end logger end end |
.loggers ⇒ Array<Logger>
Tracks all loggers that GoodJob::LogSubscriber is writing to. You can write to multiple logs by appending to this array. After updating it, you should usually call reset_logger to make sure they are all written to.
Defaults to GoodJob.logger.
170 171 172 |
# File 'lib/good_job/log_subscriber.rb', line 170 def loggers @_loggers ||= [GoodJob.logger] end |
.reset_logger ⇒ void
192 193 194 |
# File 'lib/good_job/log_subscriber.rb', line 192 def reset_logger @_logger = nil end |
Instance Method Details
#cleanup_preserved_jobs(event) ⇒ void
This method returns an undefined value.
Responds to the cleanup_preserved_jobs.good_job
notification.
141 142 143 144 145 146 147 148 |
# File 'lib/good_job/log_subscriber.rb', line 141 def cleanup_preserved_jobs(event) = event.payload[:timestamp] deleted_records_count = event.payload[:deleted_records_count] info do "GoodJob deleted #{deleted_records_count} preserved #{'job'.pluralize(deleted_records_count)} finished before #{}." end end |
#create(event) ⇒ void
This method returns an undefined value.
Responds to the create.good_job
notification.
20 21 22 23 24 25 26 27 |
# File 'lib/good_job/log_subscriber.rb', line 20 def create(event) # FIXME: This method does not match any good_job notifications. good_job = event.payload[:good_job] debug do "GoodJob created job resource with id #{good_job.id}" end end |
#cron_manager_start(event) ⇒ void
This method returns an undefined value.
Responds to the cron_manager_start.good_job
notification.
61 62 63 64 65 66 67 68 |
# File 'lib/good_job/log_subscriber.rb', line 61 def cron_manager_start(event) cron_jobs = event.payload[:cron_jobs] cron_jobs_count = cron_jobs.size info do "GoodJob started cron with #{cron_jobs_count} #{'jobs'.pluralize(cron_jobs_count)}." end end |
#finished_job_task(event) ⇒ void
This method returns an undefined value.
Responds to the finished_job_task.good_job
notification.
40 41 42 43 44 45 46 47 |
# File 'lib/good_job/log_subscriber.rb', line 40 def finished_job_task(event) exception = event.payload[:error] return unless exception error do "GoodJob error: #{exception}\n #{exception.backtrace}" end end |
#finished_timer_task(event) ⇒ void
This method returns an undefined value.
Responds to the finished_timer_task.good_job
notification.
30 31 32 33 34 35 36 37 |
# File 'lib/good_job/log_subscriber.rb', line 30 def finished_timer_task(event) exception = event.payload[:error] return unless exception error do "GoodJob error: #{exception}\n #{exception.backtrace}" end end |
#logger ⇒ Logger
Get the logger associated with this GoodJob::LogSubscriber instance.
154 155 156 |
# File 'lib/good_job/log_subscriber.rb', line 154 def logger GoodJob::LogSubscriber.logger end |
#notifier_listen(event) ⇒ void
This method returns an undefined value.
Responds to the notifier_listen.good_job
notification.
109 110 111 112 113 |
# File 'lib/good_job/log_subscriber.rb', line 109 def notifier_listen(event) # rubocop:disable Lint/UnusedMethodArgument info do "Notifier subscribed with LISTEN" end end |
#notifier_notified(event) ⇒ void
This method returns an undefined value.
Responds to the notifier_notified.good_job
notification.
116 117 118 119 120 121 122 |
# File 'lib/good_job/log_subscriber.rb', line 116 def notifier_notified(event) payload = event.payload[:payload] debug do "Notifier received payload: #{payload}" end end |
#notifier_notify_error(event) ⇒ void
This method returns an undefined value.
Responds to the notifier_notify_error.good_job
notification.
125 126 127 128 129 130 131 |
# File 'lib/good_job/log_subscriber.rb', line 125 def notifier_notify_error(event) error = event.payload[:error] error do "Notifier errored: #{error}" end end |
#notifier_unlisten(event) ⇒ void
This method returns an undefined value.
Responds to the notifier_unlisten.good_job
notification.
134 135 136 137 138 |
# File 'lib/good_job/log_subscriber.rb', line 134 def notifier_unlisten(event) # rubocop:disable Lint/UnusedMethodArgument info do "Notifier unsubscribed with UNLISTEN" end end |
#perform_job(event) ⇒ void
This method returns an undefined value.
Responds to the perform_job.good_job
notification.
98 99 100 101 102 103 104 105 106 |
# File 'lib/good_job/log_subscriber.rb', line 98 def perform_job(event) good_job = event.payload[:good_job] process_id = event.payload[:process_id] thread_name = event.payload[:thread_name] info(tags: [process_id, thread_name]) do "Executed GoodJob #{good_job.id}" end end |
#scheduler_create_pool(event) ⇒ void
This method returns an undefined value.
Responds to the scheduler_create_pool.good_job
notification.
50 51 52 53 54 55 56 57 58 |
# File 'lib/good_job/log_subscriber.rb', line 50 def scheduler_create_pool(event) max_threads = event.payload[:max_threads] performer_name = event.payload[:performer_name] process_id = event.payload[:process_id] info(tags: [process_id]) do "GoodJob started scheduler with queues=#{performer_name} max_threads=#{max_threads}." end end |
#scheduler_restart_pools(event) ⇒ void
This method returns an undefined value.
Responds to the scheduler_restart_pools.good_job
notification.
89 90 91 92 93 94 95 |
# File 'lib/good_job/log_subscriber.rb', line 89 def scheduler_restart_pools(event) process_id = event.payload[:process_id] info(tags: [process_id]) do "GoodJob scheduler has restarted." end end |
#scheduler_shutdown(event) ⇒ void
This method returns an undefined value.
Responds to the scheduler_shutdown.good_job
notification.
80 81 82 83 84 85 86 |
# File 'lib/good_job/log_subscriber.rb', line 80 def scheduler_shutdown(event) process_id = event.payload[:process_id] info(tags: [process_id]) do "GoodJob scheduler is shut down." end end |
#scheduler_shutdown_start(event) ⇒ void
This method returns an undefined value.
Responds to the scheduler_shutdown_start.good_job
notification.
71 72 73 74 75 76 77 |
# File 'lib/good_job/log_subscriber.rb', line 71 def scheduler_shutdown_start(event) process_id = event.payload[:process_id] info(tags: [process_id]) do "GoodJob shutting down scheduler..." end end |