Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

Rails 4.2 ActiveJob job id mismatch #122

Open
hqm42 opened this issue Feb 5, 2018 · 5 comments
Open

Rails 4.2 ActiveJob job id mismatch #122

hqm42 opened this issue Feb 5, 2018 · 5 comments

Comments

@hqm42
Copy link

hqm42 commented Feb 5, 2018

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
@kenaniah
Copy link
Collaborator

kenaniah commented Feb 5, 2018

What version of the gem did you run this against?

@hqm42
Copy link
Author

hqm42 commented Feb 6, 2018

v1.0.1

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

@kenaniah
Copy link
Collaborator

kenaniah commented Feb 7, 2018

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?

@hqm42
Copy link
Author

hqm42 commented Feb 7, 2018

My fix is a backport of this PR for rails 5: rails/rails#25961

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

@guapolo
Copy link

guapolo commented Nov 1, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants