Skip to content

Commit bb5fd3c

Browse files
committed
AP-513 improving order of operations
- co-authored with @danschmidt5189 - some logs were still not getting request_id logged - we believe there an issue with when the two around_performs were called - this commit should eliminate that problem
1 parent f0f5ce3 commit bb5fd3c

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

app/jobs/application_job.rb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
class ApplicationJob < ActiveJob::Base
2-
attr_reader :request_id
3-
42
before_enqueue do
53
arguments << { request_id: Current.request_id } if Current.request_id
64
end
75

8-
around_perform do |job, block|
9-
@request_id = job.arguments.pop[:request_id] if job.arguments.last.is_a?(Hash) && job.arguments.last.key?(:request_id)
10-
block.call
11-
end
6+
before_perform :log_job_metadata
127

13-
around_perform :log_job_metadata
8+
def request_id
9+
if !defined? @request_id
10+
if arguments.last.is_a?(Hash) && arguments.last.key?(:request_id)
11+
@request_id = arguments.pop[:request_id]
12+
else
13+
@request_id = nil
14+
end
15+
end
16+
@request_id
17+
end
1418

1519
def today
1620
@today ||= Time.zone.now.strftime('%Y%m%d')
1721
end
1822

1923
def log_job_metadata
20-
logger.with_fields = { activejob_id: job_id, request_id: @request_id }
21-
yield
24+
logger.with_fields = { activejob_id: job_id, request_id: }
2225
end
2326

2427
# Log an exception

0 commit comments

Comments
 (0)