mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
DEV: Prevent defer stats exception when thread aborted (#19863)
When the thread is aborted, an exception is raised before the `start` of a job is set, and therefore raises an exception in the `ensure` block. This commit checks that `start` exists, and also adds `abort_on_exception=true` so that this issue would have caused test failures.
This commit is contained in:
@ -191,6 +191,18 @@ module Discourse
|
||||
|
||||
reset_job_exception_stats!
|
||||
|
||||
if Rails.env.test?
|
||||
def self.catch_job_exceptions!
|
||||
raise "tests only" if !Rails.env.test?
|
||||
@catch_job_exceptions = true
|
||||
end
|
||||
|
||||
def self.reset_catch_job_exceptions!
|
||||
raise "tests only" if !Rails.env.test?
|
||||
remove_instance_variable(:@catch_job_exceptions)
|
||||
end
|
||||
end
|
||||
|
||||
# Log an exception.
|
||||
#
|
||||
# If your code is in a scheduled job, it is recommended to use the
|
||||
@ -220,7 +232,7 @@ module Discourse
|
||||
{ current_db: cm.current_db, current_hostname: cm.current_hostname }.merge(context),
|
||||
)
|
||||
|
||||
raise ex if Rails.env.test?
|
||||
raise ex if Rails.env.test? && !@catch_job_exceptions
|
||||
end
|
||||
|
||||
# Expected less matches than what we got in a find
|
||||
|
Reference in New Issue
Block a user