discourse/plugins/automation/app/jobs/regular/discourse_automation_trigger.rb
Osama Sayegh 3d4faf3272
FEATURE: Merge discourse-automation (#26432)
Automation (previously known as discourse-automation) is now a core plugin.
2024-04-03 18:20:43 +03:00

32 lines
884 B
Ruby

# frozen_string_literal: true
module Jobs
class DiscourseAutomationTrigger < ::Jobs::Base
RETRY_TIMES = [5.minute, 15.minute, 120.minute]
sidekiq_options retry: RETRY_TIMES.size
sidekiq_retry_in do |count, exception|
# returning nil/0 will trigger the default sidekiq
# retry formula
#
# See https://github.com/mperham/sidekiq/blob/3330df0ee37cfd3e0cd3ef01e3e66b584b99d488/lib/sidekiq/job_retry.rb#L216-L234
case exception.wrapped
when SocketError
return RETRY_TIMES[count]
end
end
def execute(args)
automation = DiscourseAutomation::Automation.find_by(id: args[:automation_id], enabled: true)
return if !automation
context = DiscourseAutomation::Automation.deserialize_context(args[:context])
automation.running_in_background!
automation.trigger!(context)
end
end
end