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:
Sam
2022-08-03 12:53:26 +10:00
committed by GitHub
parent c99f658a9e
commit bfe502012d
2 changed files with 53 additions and 0 deletions

View File

@ -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,