reidmorrison / rails_semantic_logger

Rails Semantic Logger replaces the Rails default logger with Semantic Logger
https://logger.rocketjob.io/rails
Apache License 2.0
320 stars 114 forks source link

Fix enqueue messages for ActiveJob #192

Closed claracodes closed 10 months ago

claracodes commented 11 months ago

Description of issue:

We found an issue with the logs of ActiveJobs. When a job has an error or throws an abort or Rails Semantic Logger with still log "Enqueued Job..." despite the job not being enqueued.

class NoOpJob < ApplicationJob
  before_enqueue -> { throw :abort }
end

NoOpJob.perform_later
# => false
# 2023-07-26 15:03:18.497244 I [15994:5240 subscriber.rb:149] Rails -- Enqueued NoOpJob (Job ID: 1f5c3c34-dfd0-4318-b83e-a31dc179812e) to GoodJob(default) -- { :event_name => "enqueue.active_job", :adapter => "GoodJob", :queue => "default", :job_class => "NoOpJob", :job_id => "1f5c3c34-dfd0-4318-b83e-a31dc179812e", :provider_job_id => nil, :arguments => "[\n\n]" }

Please find the corresponding log messages in the Rails Repo that differentiate between three events: errors, :abort and successful enqueing.

Description of solution

We extended both methods #enqueue and #enqueue_at and also added test cases for those.

class NoOpJob < ApplicationJob
  before_enqueue -> { throw :abort }
end

NoOpJob.perform_later
# => false
2023-07-26 15:04:37.069003 I [16286:5240 subscriber.rb:149] Rails -- Failed enqueuing NoOpJob (Job ID: 10dd3846-c887-4757-893f-88ae6b2d4ae5) to GoodJob(default), a before_enqueue callback halted the enqueuing execution. -- { :event_name => "enqueue.active_job", :adapter => "GoodJob", :queue => "default", :job_class => "NoOpJob", :job_id => "10dd3846-c887-4757-893f-88ae6b2d4ae5", :provider_job_id => nil, :arguments => "[\n\n]" }
NoOpJob.set(wait: 5.minutes).perform_later
2023-07-26 15:06:13.494036 I [16286:5240 subscriber.rb:149] Rails -- Failed enqueuing NoOpJob (Job ID: 2f27e233-8be4-4e37-a151-84d308e05a1f) to GoodJob(default), a before_enqueue callback halted the enqueuing execution. -- { :event_name => "enqueue_at.active_job", :adapter => "GoodJob", :queue => "default", :job_class => "NoOpJob", :job_id => "2f27e233-8be4-4e37-a151-84d308e05a1f", :provider_job_id => nil, :arguments => "[\n\n]" }
reidmorrison commented 10 months ago

Thank you, and great tests too. :tada: