FIX: 'cancel_scheduled_job' was deleting all jobs in multisite
This commit is contained in:
parent
7e4503dd99
commit
7db2083d45
|
@ -236,18 +236,22 @@ module Jobs
|
|||
enqueue_in(secs, job_name, opts)
|
||||
end
|
||||
|
||||
def self.cancel_scheduled_job(job_name, params={})
|
||||
scheduled_for(job_name, params).each(&:delete)
|
||||
def self.cancel_scheduled_job(job_name, opts={})
|
||||
scheduled_for(job_name, opts).each(&:delete)
|
||||
end
|
||||
|
||||
def self.scheduled_for(job_name, params={})
|
||||
params = params.with_indifferent_access
|
||||
def self.scheduled_for(job_name, opts={})
|
||||
opts = opts.with_indifferent_access
|
||||
unless opts.delete(:all_sites)
|
||||
opts[:current_site_id] ||= RailsMultisite::ConnectionManagement.current_db
|
||||
end
|
||||
|
||||
job_class = "Jobs::#{job_name.to_s.camelcase}"
|
||||
Sidekiq::ScheduledSet.new.select do |scheduled_job|
|
||||
if scheduled_job.klass.to_s == job_class
|
||||
matched = true
|
||||
job_params = scheduled_job.item["args"][0].with_indifferent_access
|
||||
params.each do |key, value|
|
||||
opts.each do |key, value|
|
||||
if job_params[key] != value
|
||||
matched = false
|
||||
break
|
||||
|
|
|
@ -87,12 +87,18 @@ describe Jobs do
|
|||
|
||||
expect(scheduled_jobs.size).to eq(0)
|
||||
|
||||
Jobs.enqueue_in(1.year, :run_heartbeat, topic_id: 1234)
|
||||
Jobs.enqueue_in(2.years, :run_heartbeat, topic_id: 5678)
|
||||
Jobs.enqueue_in(1.year, :run_heartbeat, topic_id: 123)
|
||||
Jobs.enqueue_in(2.years, :run_heartbeat, topic_id: 456)
|
||||
Jobs.enqueue_in(3.years, :run_heartbeat, topic_id: 123, current_site_id: 'foo')
|
||||
Jobs.enqueue_in(4.years, :run_heartbeat, topic_id: 123, current_site_id: 'bar')
|
||||
|
||||
expect(scheduled_jobs.size).to eq(2)
|
||||
expect(scheduled_jobs.size).to eq(4)
|
||||
|
||||
Jobs.cancel_scheduled_job(:run_heartbeat, topic_id: 1234)
|
||||
Jobs.cancel_scheduled_job(:run_heartbeat, topic_id: 123)
|
||||
|
||||
expect(scheduled_jobs.size).to eq(3)
|
||||
|
||||
Jobs.cancel_scheduled_job(:run_heartbeat, topic_id: 123, all_sites: true)
|
||||
|
||||
expect(scheduled_jobs.size).to eq(1)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue