Skip to content

Commit

Permalink
adds option for silencing logging for heartbeats
Browse files Browse the repository at this point in the history
  • Loading branch information
jlvallelonga committed Oct 15, 2024
1 parent 51c75be commit dedae3f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 13 additions & 5 deletions app/models/solid_queue/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
5 changes: 5 additions & 0 deletions lib/solid_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,6 +60,10 @@ def silence_polling?
silence_polling
end

def silence_heartbeats?
silence_heartbeats
end

def preserve_finished_jobs?
preserve_finished_jobs
end
Expand Down

0 comments on commit dedae3f

Please sign in to comment.