mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 11:33:44 +08:00
0034cbda8a
Moves the topic timer jobs from being scheduled ahead of time with enqueue_at to a 5 minute scheduled run like bookmark reminders, in a new job called Jobs::EnqueueTopicTimers. Backwards compatibility is maintained by checking if an existing topic timer job is enqueued in sidekiq for the timer, and if it is not running it inside the new job. The functionality to close/open a topic if it is in the opposite state still remains in the after_save block of TopicTimer, with further commentary, which is used for Open/Close Temporarily. This also removes the ensure_consistency! functionality of topic timers as it is no longer needed; the new job will always pick up the timers because they are not stored in a fragile state of sidekiq.
26 lines
694 B
Ruby
26 lines
694 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
|
|
# Runs periodically to look through topic timers that are ready to execute,
|
|
# and enqueues their related jobs.
|
|
#
|
|
# Any leftovers will be caught in the next run, because execute_at will
|
|
# be < now, and topic timers that have run are deleted on completion or
|
|
# otherwise have their execute_at time modified.
|
|
class TopicTimerEnqueuer < ::Jobs::Scheduled
|
|
every 1.minute
|
|
|
|
def execute(_args = nil)
|
|
timers = TopicTimer.pending_timers
|
|
|
|
timers.find_each do |timer|
|
|
|
|
# the typed job may not enqueue if it has already
|
|
# been scheduled with enqueue_at
|
|
timer.enqueue_typed_job
|
|
end
|
|
end
|
|
end
|
|
end
|