Rails 4.2 get delayed job id from active job

后端 未结 4 658
南笙
南笙 2021-01-02 00:47

Any idea how to get the Delayed::Job id from the ActiveJob enqueuing? When I enqueue a job I get back an instance of ActiveJob::Base with a @

4条回答
  •  醉话见心
    2021-01-02 01:03

    In case anyone finds this in the future: Rails just accepted a patch to allow you to get this id from provider_job_id in Rails 5. You can get it to work with a patch like

    ActiveJob::QueueAdapters::DelayedJobAdapter.singleton_class.prepend(Module.new do
      def enqueue(job)
        provider_job = super
        job.provider_job_id = provider_job.id
        provider_job
      end
    
      def enqueue_at(job, timestamp)
        provider_job = super
        job.provider_job_id = provider_job.id
        provider_job
      end
    end)
    

提交回复
热议问题