mirror of
https://github.com/discourse/discourse.git
synced 2024-12-20 12:43:47 +08:00
c6f2459cc4
There was an issue with the TopicTimerEnqueuer where any timer that failed to enqueue_typed_job with an error would prevent all other pending timers after the one that errored from running. To mitigate this we just capture the error and log it (so we can still fix it if needed for bug crushing) and proceed with the rest of the timer enqueues. The commit https://github.com/discourse/discourse/pull/13544 highlighted this issue originally in hosted sites. <!-- NOTE: All pull requests should have tests (rspec in Ruby, qunit in JavaScript). If your code does not include test coverage, please include an explanation of why it was omitted. -->
28 lines
844 B
Ruby
28 lines
844 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)
|
|
TopicTimer.pending_timers.find_each do |timer|
|
|
|
|
# the typed job may not enqueue if it has already
|
|
# been scheduled with enqueue_at
|
|
begin
|
|
timer.enqueue_typed_job
|
|
rescue => err
|
|
Discourse.warn_exception(err, message: "Error when attempting to enqueue topic timer job for timer #{timer.id}")
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|