mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FIX: 'cancel_scheduled_job' was deleting all jobs in multisite
This commit is contained in:
parent
7e4503dd99
commit
7db2083d45
2 changed files with 19 additions and 9 deletions
|
@ -236,18 +236,22 @@ module Jobs
|
||||||
enqueue_in(secs, job_name, opts)
|
enqueue_in(secs, job_name, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.cancel_scheduled_job(job_name, params={})
|
def self.cancel_scheduled_job(job_name, opts={})
|
||||||
scheduled_for(job_name, params).each(&:delete)
|
scheduled_for(job_name, opts).each(&:delete)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.scheduled_for(job_name, params={})
|
def self.scheduled_for(job_name, opts={})
|
||||||
params = params.with_indifferent_access
|
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}"
|
job_class = "Jobs::#{job_name.to_s.camelcase}"
|
||||||
Sidekiq::ScheduledSet.new.select do |scheduled_job|
|
Sidekiq::ScheduledSet.new.select do |scheduled_job|
|
||||||
if scheduled_job.klass.to_s == job_class
|
if scheduled_job.klass.to_s == job_class
|
||||||
matched = true
|
matched = true
|
||||||
job_params = scheduled_job.item["args"][0].with_indifferent_access
|
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
|
if job_params[key] != value
|
||||||
matched = false
|
matched = false
|
||||||
break
|
break
|
||||||
|
|
|
@ -87,12 +87,18 @@ describe Jobs do
|
||||||
|
|
||||||
expect(scheduled_jobs.size).to eq(0)
|
expect(scheduled_jobs.size).to eq(0)
|
||||||
|
|
||||||
Jobs.enqueue_in(1.year, :run_heartbeat, topic_id: 1234)
|
Jobs.enqueue_in(1.year, :run_heartbeat, topic_id: 123)
|
||||||
Jobs.enqueue_in(2.years, :run_heartbeat, topic_id: 5678)
|
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)
|
expect(scheduled_jobs.size).to eq(1)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue