mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FIX: Prevent infinite loop of automations triggering each other (#26814)
It's currently possible to setup multiple automation rules that trigger each other resulting in an infinite loop. To prevent that, this commit adds a global "circuit breaker" that prevents all automations from triggering while an automation rule is executing. Internal topic: t/124365.
This commit is contained in:
@ -134,11 +134,23 @@ module DiscourseAutomation
|
||||
|
||||
def trigger!(context = {})
|
||||
if enabled
|
||||
if scriptable.background && !running_in_background
|
||||
trigger_in_background!(context)
|
||||
else
|
||||
triggerable&.on_call&.call(self, serialized_fields)
|
||||
scriptable.script.call(context, serialized_fields, self)
|
||||
if active_id = DiscourseAutomation.get_active_automation
|
||||
Rails.logger.warn(<<~TEXT.strip)
|
||||
[automation] potential automations infinite loop detected: skipping automation #{self.id} because automation #{active_id} is still executing.")
|
||||
TEXT
|
||||
return
|
||||
end
|
||||
|
||||
begin
|
||||
DiscourseAutomation.set_active_automation(self.id)
|
||||
if scriptable.background && !running_in_background
|
||||
trigger_in_background!(context)
|
||||
else
|
||||
triggerable&.on_call&.call(self, serialized_fields)
|
||||
scriptable.script.call(context, serialized_fields, self)
|
||||
end
|
||||
ensure
|
||||
DiscourseAutomation.set_active_automation(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user