Skip to content

Commit 443a13a

Browse files
committed
Apply sagittarius context to all ActiveJob classes
1 parent f9da9ec commit 443a13a

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

app/jobs/application_job.rb

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,29 @@ class ApplicationJob < ActiveJob::Base
88
# Most jobs are safe to ignore if the underlying records are no longer available
99
# discard_on ActiveJob::DeserializationError
1010

11-
retry_on StandardError, wait: :polynomially_longer, attempts: 10
11+
ActiveJob::Base.instance_eval do
12+
retry_on StandardError, wait: :polynomially_longer, attempts: 10
1213

13-
before_enqueue do |job|
14-
next if job.arguments.first&.try(:key?, :sagittarius_context)
14+
before_enqueue do |job|
15+
possible_context = job.arguments.last
16+
next if possible_context.is_a?(Hash) && possible_context&.try(:key?, :sagittarius_context)
1517

16-
job.arguments.unshift Code0::ZeroTrack::Context.current.to_h.merge(sagittarius_context: true)
17-
end
18+
job.arguments << Code0::ZeroTrack::Context.current.to_h.merge(sagittarius_context: true)
19+
end
1820

19-
around_perform do |job, block|
20-
context = job.arguments.shift
21-
context.delete(:sagittarius_context)
22-
source_application = context.fetch(Code0::ZeroTrack::Context.log_key(:application), nil)
23-
Code0::ZeroTrack::Context.with_context(
24-
**context,
25-
application: 'good_job',
26-
source_application: source_application,
27-
job_id: job.job_id,
28-
job_class: self.class.name
29-
) do
30-
block.call
21+
around_perform do |job, block|
22+
context = job.arguments.pop
23+
context.delete(:sagittarius_context)
24+
source_application = context.fetch(Code0::ZeroTrack::Context.log_key(:application), nil)
25+
Code0::ZeroTrack::Context.with_context(
26+
**context,
27+
application: 'good_job',
28+
source_application: source_application,
29+
job_id: job.job_id,
30+
job_class: self.class.name
31+
) do
32+
block.call
33+
end
3134
end
3235
end
3336
end

0 commit comments

Comments
 (0)