rails: ActiveJob not returning true job_id

ActiveJob does not return provider’s job_id but uuid instead.

I use Que which stores an incremental id for each job (as a numeric value) in database. When executing MyJob.perform_later(MyRecord.first) the returning job_id is not the one from the database but ActiveJob’s unique value instead. The job_id should be the one from the database in this case.

Ref: https://github.com/chanks/que/issues/84

I mad a workaround for now:

# config/initializers/active_job_fix.rb
class ActiveJob::Base
  def enqueue(options={})
    self.scheduled_at = options[:wait].seconds.from_now.to_f if options[:wait]
    self.scheduled_at = options[:wait_until].to_f if options[:wait_until]
    self.queue_name   = self.class.queue_name_from_part(options[:queue]) if options[:queue]
    # hide this to set job_id before logger picks it (I would change ActiveJob::Logger before_enqueue to after_enqueue)
    # run_callbacks :enqueue do
      if self.scheduled_at
        j = self.class.queue_adapter.enqueue_at self, self.scheduled_at
      else
        j = self.class.queue_adapter.enqueue self
      end
      self.job_id = j.attrs["job_id"] || j.attrs["id"] # this should be set inside each adapter
    # end
    self
  end
end

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 23 (23 by maintainers)

Commits related to this issue

Most upvoted comments

Just put in a PR for DelayedJob https://github.com/rails/rails/pull/19910