From bb5fd3ca0906bb72b32d0c291f6e1f5a7ddf5373 Mon Sep 17 00:00:00 2001 From: Jason Raitz Date: Fri, 13 Feb 2026 16:39:23 -0500 Subject: [PATCH] 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 --- app/jobs/application_job.rb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) 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