DEV: Add debug logging for automation recurring trigger (#28829)

We're seeing a problem where some recurring automations end up in a state where they don't have any `pending_automations` records scheduled which effectively makes the recurring automation dead. We need to add some debugging to figure out what might be causing this problem.

Internal topic: t/138045.
This commit is contained in:
Osama Sayegh 2024-09-11 01:29:15 +03:00 committed by GitHub
parent 917621ed80
commit 91ba2a4aab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 0 deletions

View File

@ -2,3 +2,6 @@ plugins:
discourse_automation_enabled:
default: false
client: true
discourse_automation_enable_recurring_debug:
default: false
hidden: true

View File

@ -32,6 +32,16 @@ module DiscourseAutomation
previous_frequency != frequency
automation.pending_automations.destroy_all
elsif automation.pending_automations.present?
log_debugging_info(
id: automation.id,
start_date:,
interval:,
frequency:,
previous_start_date:,
previous_interval:,
previous_frequency:,
now: Time.zone.now,
)
return
end
@ -87,8 +97,30 @@ module DiscourseAutomation
if next_trigger_date && next_trigger_date > Time.zone.now
automation.pending_automations.create!(execute_at: next_trigger_date)
else
log_debugging_info(
id: automation.id,
start_date:,
interval:,
frequency:,
previous_start_date:,
previous_interval:,
previous_frequency:,
byday:,
interval_end:,
next_trigger_date:,
now: Time.zone.now,
)
nil
end
end
def self.log_debugging_info(context)
return if !SiteSetting.discourse_automation_enable_recurring_debug
str = "[automation] scheduling recurring automation debug: "
str += context.map { |k, v| "#{k}=#{v.inspect}" }.join(", ")
Rails.logger.warn(str)
end
end
end
end