FEATURE: more context for error reporting on jobs fails

This commit is contained in:
Sam
2018-08-16 12:38:25 +10:00
parent c8b5e6baae
commit 1f17b84b63

View File

@@ -119,6 +119,11 @@ module Jobs
RailsMultisite::ConnectionManagement.all_dbs RailsMultisite::ConnectionManagement.all_dbs
end end
logster_env = {}
Logster.add_to_env(logster_env, :current_db, 'default')
Logster.add_to_env(logster_env, :job, self.class.to_s)
Thread.current[Logster::Logger::LOGSTER_ENV] = logster_env
exceptions = [] exceptions = []
dbs.each do |db| dbs.each do |db|
begin begin
@@ -129,6 +134,7 @@ module Jobs
I18n.locale = SiteSetting.default_locale || "en" I18n.locale = SiteSetting.default_locale || "en"
I18n.ensure_all_loaded! I18n.ensure_all_loaded!
begin begin
Logster.add_to_env(logster_env, :db, db)
execute(opts) execute(opts)
rescue => e rescue => e
exception[:ex] = e exception[:ex] = e
@@ -140,6 +146,7 @@ module Jobs
exception[:other] = { problem_db: db } exception[:other] = { problem_db: db }
ensure ensure
total_db_time += Instrumenter.stats.duration_ms total_db_time += Instrumenter.stats.duration_ms
Thread.current[Logster::Logger::LOGSTER_ENV] = nil
end end
end end
@@ -147,6 +154,8 @@ module Jobs
end end
end end
Thread.current[Logster::Logger::LOGSTER_ENV] = nil
if exceptions.length > 0 if exceptions.length > 0
exceptions.each do |exception_hash| exceptions.each do |exception_hash|
Discourse.handle_job_exception(exception_hash[:ex], error_context(opts, exception_hash[:code], exception_hash[:other])) Discourse.handle_job_exception(exception_hash[:ex], error_context(opts, exception_hash[:code], exception_hash[:other]))