mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 00:55:06 +08:00
FIX: avoid usage of dig when looking for job class (#17772)
`{a: "a"}.dig(:a, :b)` will result in an exception, since ruby assumes that `"a"` will be another hash it can look up the `:b` key on.
This commit is contained in:
parent
035f5d7a5d
commit
3b42e69174
|
@ -175,9 +175,13 @@ module Discourse
|
|||
context ||= {}
|
||||
parent_logger ||= Sidekiq
|
||||
|
||||
job = context.dig(:job, "class")
|
||||
if job
|
||||
job_exception_stats[job] += 1
|
||||
job = context[:job]
|
||||
|
||||
if Hash === job
|
||||
job_class = job["class"]
|
||||
if job_class
|
||||
job_exception_stats[job_class] += 1
|
||||
end
|
||||
end
|
||||
|
||||
cm = RailsMultisite::ConnectionManagement
|
||||
|
|
|
@ -342,6 +342,9 @@ RSpec.describe Discourse do
|
|||
|
||||
describe "#job_exception_stats" do
|
||||
|
||||
class FakeTestError < StandardError
|
||||
end
|
||||
|
||||
before do
|
||||
Discourse.reset_job_exception_stats!
|
||||
end
|
||||
|
@ -350,6 +353,12 @@ RSpec.describe Discourse do
|
|||
Discourse.reset_job_exception_stats!
|
||||
end
|
||||
|
||||
it "should not fail on incorrectly shaped hash" do
|
||||
expect do
|
||||
Discourse.handle_job_exception(FakeTestError.new, { job: "test" })
|
||||
end.to raise_error(FakeTestError)
|
||||
end
|
||||
|
||||
it "should collect job exception stats" do
|
||||
|
||||
# see MiniScheduler Manager which reports it like this
|
||||
|
@ -361,7 +370,7 @@ RSpec.describe Discourse do
|
|||
|
||||
# re-raised unconditionally in test env
|
||||
2.times do
|
||||
expect { Discourse.handle_job_exception(StandardError.new, exception_context) }.to raise_error(StandardError)
|
||||
expect { Discourse.handle_job_exception(FakeTestError.new, exception_context) }.to raise_error(FakeTestError)
|
||||
end
|
||||
|
||||
exception_context = {
|
||||
|
@ -369,7 +378,7 @@ RSpec.describe Discourse do
|
|||
job: { "class" => Jobs::PollMailbox }
|
||||
}
|
||||
|
||||
expect { Discourse.handle_job_exception(StandardError.new, exception_context) }.to raise_error(StandardError)
|
||||
expect { Discourse.handle_job_exception(FakeTestError.new, exception_context) }.to raise_error(FakeTestError)
|
||||
|
||||
expect(Discourse.job_exception_stats).to eq({
|
||||
Jobs::PollMailbox => 1,
|
||||
|
|
Loading…
Reference in New Issue
Block a user