diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 76d43bdb..aadce01a 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,24 +1,27 @@ class ApplicationJob < ActiveJob::Base - attr_reader :request_id - before_enqueue do arguments << { request_id: Current.request_id } if Current.request_id end - around_perform do |job, block| - @request_id = job.arguments.pop[:request_id] if job.arguments.last.is_a?(Hash) && job.arguments.last.key?(:request_id) - block.call - end + before_perform :log_job_metadata - around_perform :log_job_metadata + def request_id + if !defined? @request_id + if arguments.last.is_a?(Hash) && arguments.last.key?(:request_id) + @request_id = arguments.pop[:request_id] + else + @request_id = nil + end + end + @request_id + end def today @today ||= Time.zone.now.strftime('%Y%m%d') end def log_job_metadata - logger.with_fields = { activejob_id: job_id, request_id: @request_id } - yield + logger.with_fields = { activejob_id: job_id, request_id: } end # Log an exception