sidekiq-status
sidekiq-status copied to clipboard
Rails 4.2 ActiveJob job id mismatch
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
What version of the gem did you run this against?
v1.0.1
Here is a screenshot:
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?
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.
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.