FIX: Don't enqueue topic status update job if topic is deleted.
This commit is contained in:
parent
ee449b0dd5
commit
bda20cc44a
|
@ -23,7 +23,7 @@ class TopicStatusUpdate < ActiveRecord::Base
|
|||
end
|
||||
|
||||
after_save do
|
||||
if (execute_at_changed? || user_id_changed?) && topic
|
||||
if (execute_at_changed? || user_id_changed?)
|
||||
now = Time.zone.now
|
||||
time = execute_at < now ? now : execute_at
|
||||
|
||||
|
@ -40,7 +40,9 @@ class TopicStatusUpdate < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.ensure_consistency!
|
||||
TopicStatusUpdate.where("execute_at < ?", Time.zone.now).find_each do |topic_status_update|
|
||||
TopicStatusUpdate.where("topic_status_updates.execute_at < ?", Time.zone.now)
|
||||
.find_each do |topic_status_update|
|
||||
|
||||
topic_status_update.send(
|
||||
"schedule_auto_#{self.types[topic_status_update.status_type]}_job",
|
||||
topic_status_update.execute_at
|
||||
|
@ -76,6 +78,7 @@ class TopicStatusUpdate < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def schedule_auto_open_job(time)
|
||||
return unless topic
|
||||
topic.update_status('closed', true, user) if !topic.closed
|
||||
|
||||
Jobs.enqueue_at(time, :toggle_topic_closed,
|
||||
|
@ -85,6 +88,7 @@ class TopicStatusUpdate < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def schedule_auto_close_job(time)
|
||||
return unless topic
|
||||
topic.update_status('closed', false, user) if topic.closed
|
||||
|
||||
Jobs.enqueue_at(time, :toggle_topic_closed,
|
||||
|
|
|
@ -226,6 +226,11 @@ RSpec.describe TopicStatusUpdate, type: :model do
|
|||
|
||||
Fabricate(:topic_status_update)
|
||||
|
||||
Fabricate(:topic_status_update,
|
||||
execute_at: Time.zone.now - 1.hour,
|
||||
created_at: Time.zone.now - 2.hour
|
||||
).topic.trash!
|
||||
|
||||
expect { described_class.ensure_consistency! }
|
||||
.to change { Jobs::ToggleTopicClosed.jobs.count }.by(2)
|
||||
|
||||
|
|
Loading…
Reference in New Issue