Skip to content

Commit dedae3f

Browse files
committed
adds option for silencing logging for heartbeats
1 parent 51c75be commit dedae3f

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ There are several settings that control how Solid Queue works that you can set a
231231
- `process_alive_threshold`: how long to wait until a process is considered dead after its last heartbeat—defaults to 5 minutes.
232232
- `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.
233233
- `silence_polling`: whether to silence Active Record logs emitted when polling for both workers and dispatchers—defaults to `true`.
234+
- `silence_heartbeats`: whether to silence Active Record logs emitted for heartbeats for both workers and dispatchers—defaults to `false`.
234235
- `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.
235236
- `preserve_finished_jobs`: whether to keep finished jobs in the `solid_queue_jobs` table—defaults to `true`.
236237
- `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.

app/models/solid_queue/process.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def self.register(**attributes)
2020
end
2121

2222
def heartbeat
23-
# Clear any previous changes before locking, for example, in case a previous heartbeat
24-
# failed because of a DB issue (with SQLite depending on configuration, a BusyException
25-
# is not rare) and we still have the unpersisted value
26-
restore_attributes
27-
with_lock { touch(:last_heartbeat_at) }
23+
if SolidQueue.silence_heartbeats? && ActiveRecord::Base.logger
24+
ActiveRecord::Base.logger.silence { perform_heartbeat }
25+
else
26+
perform_heartbeat
27+
end
2828
end
2929

3030
def deregister(pruned: false)
@@ -44,4 +44,12 @@ def deregister(pruned: false)
4444
def supervised?
4545
supervisor_id.present?
4646
end
47+
48+
def perform_heartbeat
49+
# Clear any previous changes before locking, for example, in case a previous heartbeat
50+
# failed because of a DB issue (with SQLite depending on configuration, a BusyException
51+
# is not rare) and we still have the unpersisted value
52+
restore_attributes
53+
with_lock { touch(:last_heartbeat_at) }
54+
end
4755
end

lib/solid_queue.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module SolidQueue
3333
mattr_accessor :shutdown_timeout, default: 5.seconds
3434

3535
mattr_accessor :silence_polling, default: true
36+
mattr_accessor :silence_heartbeats, default: false
3637

3738
mattr_accessor :supervisor_pidfile
3839
mattr_accessor :supervisor, default: false
@@ -59,6 +60,10 @@ def silence_polling?
5960
silence_polling
6061
end
6162

63+
def silence_heartbeats?
64+
silence_heartbeats
65+
end
66+
6267
def preserve_finished_jobs?
6368
preserve_finished_jobs
6469
end

0 commit comments

Comments
 (0)