refactor(automations): fold expiry check into skip_reason_for guard chain
This commit is contained in:
@@ -8,8 +8,6 @@ class AutomationRules::ProcessPendingExecutionJob < ApplicationJob
|
||||
# Atomic claim: a duplicate enqueue (overlapping sweep or stale reclaim) loses here and returns.
|
||||
return unless pending_execution.claim!
|
||||
|
||||
return pending_execution.update!(status: :skipped, skip_reason: 'expired') if expired?(pending_execution)
|
||||
|
||||
skip_reason = skip_reason_for(pending_execution)
|
||||
return pending_execution.update!(status: :skipped, skip_reason: skip_reason) if skip_reason
|
||||
|
||||
@@ -21,15 +19,22 @@ class AutomationRules::ProcessPendingExecutionJob < ApplicationJob
|
||||
|
||||
private
|
||||
|
||||
def expired?(pending_execution)
|
||||
pending_execution.due_at < AutomationRulePendingExecution::DUE_WINDOW.ago
|
||||
def skip_reason_for(pending_execution)
|
||||
return 'expired' if pending_execution.due_at < AutomationRulePendingExecution::DUE_WINDOW.ago
|
||||
|
||||
structural_skip_reason(pending_execution) || behavioral_skip_reason(pending_execution)
|
||||
end
|
||||
|
||||
def skip_reason_for(pending_execution)
|
||||
def structural_skip_reason(pending_execution)
|
||||
rule = pending_execution.automation_rule
|
||||
return 'rule_inactive' if rule.nil? || !rule.active?
|
||||
return 'flag_disabled' unless pending_execution.account.feature_enabled?('delayed_automations')
|
||||
return 'conversation_gone' if pending_execution.conversation.nil?
|
||||
|
||||
nil
|
||||
end
|
||||
|
||||
def behavioral_skip_reason(pending_execution)
|
||||
return 'episode_moved' unless pending_execution.episode_current?
|
||||
return 'conditions_changed' unless conditions_still_match?(pending_execution)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user