From 07ee06bbeb78e5699a4a5ce4bdfbe17ff70b0a27 Mon Sep 17 00:00:00 2001 From: Niklas van Schrick Date: Sat, 17 Jan 2026 17:00:06 +0100 Subject: [PATCH] Fix ActiveJob callbacks with code reloading --- app/jobs/application_job.rb | 26 -------------------------- config/initializers/active_job.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 26 deletions(-) create mode 100644 config/initializers/active_job.rb diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index 7535bb46..9ba2f8ba 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -7,30 +7,4 @@ class ApplicationJob < ActiveJob::Base # Most jobs are safe to ignore if the underlying records are no longer available # discard_on ActiveJob::DeserializationError - - ActiveJob::Base.instance_eval do - retry_on StandardError, wait: :polynomially_longer, attempts: 10 - - before_enqueue do |job| - possible_context = job.arguments.last - next if possible_context.is_a?(Hash) && possible_context&.try(:key?, :sagittarius_context) - - job.arguments << Code0::ZeroTrack::Context.current.to_h.merge(sagittarius_context: true) - end - - around_perform do |job, block| - context = job.arguments.pop - context.delete(:sagittarius_context) - source_application = context.fetch(Code0::ZeroTrack::Context.log_key(:application), nil) - Code0::ZeroTrack::Context.with_context( - **context, - application: 'good_job', - source_application: source_application, - job_id: job.job_id, - job_class: self.class.name - ) do - block.call - end - end - end end diff --git a/config/initializers/active_job.rb b/config/initializers/active_job.rb new file mode 100644 index 00000000..6f596dc3 --- /dev/null +++ b/config/initializers/active_job.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +ActiveJob::Base.instance_eval do + retry_on StandardError, wait: :polynomially_longer, attempts: 10 + + before_enqueue do |job| + possible_context = job.arguments.last + next if possible_context.is_a?(Hash) && possible_context&.try(:key?, :sagittarius_context) + + job.arguments << Code0::ZeroTrack::Context.current.to_h.merge(sagittarius_context: true) + end + + around_perform do |job, block| + context = job.arguments.pop + context.delete(:sagittarius_context) + source_application = context.fetch(Code0::ZeroTrack::Context.log_key(:application), nil) + Code0::ZeroTrack::Context.with_context( + **context, + application: 'good_job', + source_application: source_application, + job_id: job.job_id, + job_class: self.class.name + ) do + block.call + end + end +end