0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 10:37:43 +08:00
discourse/plugins/discourse-calendar/jobs/regular/discourse_post_event/bump_topic.rb
Régis Hanol fb910ca078
FIX: skip topic bump when date is in the past (#36784)
The BumpTopic job was raising Discourse::InvalidParameters when the
scheduled bump date had already passed by the time Sidekiq executed the
job. This happened because set_or_create_timer validates that timestamps
must be in the future.

Now the job checks if the date is still in the future before attempting
to create the timer. If the bump time has passed, there's nothing to do
anyway.

Also handles malformed date strings gracefully by rescuing ArgumentError
from Time.parse.
2025-12-18 21:29:06 +01:00

25 lines
597 B
Ruby
Vendored

# frozen_string_literal: true
module Jobs
class DiscoursePostEventBumpTopic < ::Jobs::Base
sidekiq_options retry: false
def execute(args)
return unless topic = Topic.find_by(id: args[:topic_id].to_i)
return unless by_user = User.find_by(id: topic.user_id)
return if args[:date].blank?
date = args[:date]
begin
date = Time.parse(date) if date.is_a?(String)
rescue ArgumentError
return
end
return if date <= Time.now.utc
topic.set_or_create_timer(TopicTimer.types[:bump], args[:date], by_user:)
end
end
end