diff --git a/README.md b/README.md index 0f9a19a0..697a6599 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,7 @@ There are several settings that control how Solid Queue works that you can set a - `process_alive_threshold`: how long to wait until a process is considered dead after its last heartbeat—defaults to 5 minutes. - `shutdown_timeout`: time the supervisor will wait since it sent the `TERM` signal to its supervised processes before sending a `QUIT` version to them requesting immediate termination—defaults to 5 seconds. - `silence_polling`: whether to silence Active Record logs emitted when polling for both workers and dispatchers—defaults to `true`. +- `silence_heartbeats`: whether to silence Active Record logs emitted for heartbeats for both workers and dispatchers—defaults to `false`. - `supervisor_pidfile`: path to a pidfile that the supervisor will create when booting to prevent running more than one supervisor in the same host, or in case you want to use it for a health check. It's `nil` by default. - `preserve_finished_jobs`: whether to keep finished jobs in the `solid_queue_jobs` table—defaults to `true`. - `clear_finished_jobs_after`: period to keep finished jobs around, in case `preserve_finished_jobs` is true—defaults to 1 day. **Note:** Right now, there's no automatic cleanup of finished jobs. You'd need to do this by periodically invoking `SolidQueue::Job.clear_finished_in_batches`, but this will happen automatically in the near future. diff --git a/app/models/solid_queue/process.rb b/app/models/solid_queue/process.rb index e81edc14..9e6a3083 100644 --- a/app/models/solid_queue/process.rb +++ b/app/models/solid_queue/process.rb @@ -20,11 +20,11 @@ def self.register(**attributes) end def heartbeat - # Clear any previous changes before locking, for example, in case a previous heartbeat - # failed because of a DB issue (with SQLite depending on configuration, a BusyException - # is not rare) and we still have the unpersisted value - restore_attributes - with_lock { touch(:last_heartbeat_at) } + if SolidQueue.silence_heartbeats? && ActiveRecord::Base.logger + ActiveRecord::Base.logger.silence { perform_heartbeat } + else + perform_heartbeat + end end def deregister(pruned: false) @@ -44,4 +44,12 @@ def deregister(pruned: false) def supervised? supervisor_id.present? end + + def perform_heartbeat + # Clear any previous changes before locking, for example, in case a previous heartbeat + # failed because of a DB issue (with SQLite depending on configuration, a BusyException + # is not rare) and we still have the unpersisted value + restore_attributes + with_lock { touch(:last_heartbeat_at) } + end end diff --git a/lib/solid_queue.rb b/lib/solid_queue.rb index e7070d26..d365186c 100644 --- a/lib/solid_queue.rb +++ b/lib/solid_queue.rb @@ -33,6 +33,7 @@ module SolidQueue mattr_accessor :shutdown_timeout, default: 5.seconds mattr_accessor :silence_polling, default: true + mattr_accessor :silence_heartbeats, default: false mattr_accessor :supervisor_pidfile mattr_accessor :supervisor, default: false @@ -59,6 +60,10 @@ def silence_polling? silence_polling end + def silence_heartbeats? + silence_heartbeats + end + def preserve_finished_jobs? preserve_finished_jobs end