mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
FEATURE: track stats around failing scheduled jobs (#17769)
* FEATURE: track stats around failing scheduled jobs Discourse.job_exception_stats can now be used to gather stats around how many regular scheduled jobs failed in the current process. This will be consumed by the Prometheus plugin and potentially other monitoring plugins.
This commit is contained in:
@ -153,6 +153,16 @@ module Discourse
|
||||
end
|
||||
end
|
||||
|
||||
def self.job_exception_stats
|
||||
@job_exception_stats
|
||||
end
|
||||
|
||||
def self.reset_job_exception_stats!
|
||||
@job_exception_stats = Hash.new(0)
|
||||
end
|
||||
|
||||
reset_job_exception_stats!
|
||||
|
||||
# Log an exception.
|
||||
#
|
||||
# If your code is in a scheduled job, it is recommended to use the
|
||||
@ -165,6 +175,11 @@ module Discourse
|
||||
context ||= {}
|
||||
parent_logger ||= Sidekiq
|
||||
|
||||
job = context.dig(:job, "class")
|
||||
if job
|
||||
job_exception_stats[job] += 1
|
||||
end
|
||||
|
||||
cm = RailsMultisite::ConnectionManagement
|
||||
parent_logger.handle_exception(ex, {
|
||||
current_db: cm.current_db,
|
||||
|
Reference in New Issue
Block a user