2024-04-03 23:20:43 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
2024-05-07 04:12:55 +08:00
|
|
|
class DiscourseAutomation::Trigger < ::Jobs::Base
|
2024-04-03 23:20:43 +08:00
|
|
|
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)
|
2024-05-07 04:12:55 +08:00
|
|
|
automation =
|
|
|
|
::DiscourseAutomation::Automation.find_by(id: args[:automation_id], enabled: true)
|
2024-04-03 23:20:43 +08:00
|
|
|
|
|
|
|
return if !automation
|
|
|
|
|
2024-05-07 04:12:55 +08:00
|
|
|
context = ::DiscourseAutomation::Automation.deserialize_context(args[:context])
|
2024-04-03 23:20:43 +08:00
|
|
|
|
|
|
|
automation.running_in_background!
|
|
|
|
automation.trigger!(context)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|