sidekiq-status icon indicating copy to clipboard operation
sidekiq-status copied to clipboard

Rails 4.2 ActiveJob job id mismatch

Open hqm42 opened this issue 7 years ago • 5 comments

In rails 4.2 the job status is reported to the sidekiq job id and the progress ends up at the ActiveJob job id resulting in two status lines in the webinterface. This should have been fixed by privider_job_id. Unfortunately provicer_job_id is broken in Rails 4.2.

I put the folliwing code in config/initializers/active_job_provider_job_id.rb to fix it:

module ActiveJob
  class Base
    class << self
      def deserialize_with_provider_job_id(job_data)
        job = deserialize_without_provider_job_id(job_data)
        job.instance_variable_set(:@provider_job_id, job_data['provider-job-id'])
        job
      end

      alias_method_chain :deserialize, :provider_job_id
    end
  end

  module QueueAdapters
    class SidekiqAdapter
      class JobWrapper
        def perform_with_provider_job_id(job_data)
          perform_without_provider_job_id(job_data.merge('provider-job-id' => jid))
        end

        alias_method_chain :perform, :provider_job_id
      end
    end
  end
end

hqm42 avatar Feb 05 '18 08:02 hqm42

What version of the gem did you run this against?

kenaniah avatar Feb 05 '18 22:02 kenaniah

v1.0.1

Here is a screenshot: screenshot from 2018-02-06 08-56-39

hqm42 avatar Feb 06 '18 07:02 hqm42

Thanks for the report! I'll try digging into the best fix for this when I have some free time. Ideally, it would be nice to see this working properly in Rails 4.2 environments. Could I ask you to also post how you launched the job and/or steps to reproduce?

kenaniah avatar Feb 07 '18 00:02 kenaniah

My fix is a backport of this PR for rails 5: https://github.com/rails/rails/pull/25961

I will try to write some specs to reproduce this issue.

hqm42 avatar Feb 07 '18 08:02 hqm42

I got the jid with a scheduled job on rails 4.2 with:

job = SomeJob.set(wait: 5.seconds).perform_later
jid = Sidekiq::ScheduledSet.new.find{|j| j.args.first["job_id"] == job.job_id }.item['jid']

Not efficient if there are many jobs on the queue, since it's a linear search.

guapolo avatar Nov 01 '18 05:11 guapolo