Log async rule run failures to debug log (#3045)

* Log async rule run failures to debug log

* Propagate auto-categorize provider failures
This commit is contained in:
Sure Admin (bot)
2026-08-16 00:36:43 +02:00
committed by GitHub
parent c9fbfd9f71
commit 75aa16e4e2
6 changed files with 233 additions and 12 deletions
+1 -2
View File
@@ -30,8 +30,7 @@ class Family::AutoCategorizer
)
unless result.success?
Rails.logger.error("Failed to auto-categorize transactions for family #{family.id}: #{result.error.message}")
return 0
raise Error, "Failed to auto-categorize transactions: #{result.error.message}"
end
modified_count = 0
+43 -5
View File
@@ -34,13 +34,51 @@ class RuleRun < ApplicationRecord
# Thread-safe method to complete a job and update the run
def complete_job!(modified_count: 0)
with_lock do
increment!(:transactions_modified, modified_count)
decrement!(:pending_jobs_count)
self.transactions_modified += modified_count
self.pending_jobs_count = [ pending_jobs_count - 1, 0 ].max
# If all jobs are done, mark as success
if pending_jobs_count <= 0
update!(status: "success")
end
self.status = "success" if pending_jobs_count <= 0 && !failed?
save!
end
end
def fail_job!(error:, source:, transaction_ids: [])
should_log = false
with_lock do
should_log = !failed?
self.pending_jobs_count = [ pending_jobs_count - 1, 0 ].max
self.status = "failed"
self.error_message = "#{error.class}: #{error.message}"
save!
end
capture_failure_debug_log(error:, source:, transaction_ids:) if should_log
end
private
def capture_failure_debug_log(error:, source:, transaction_ids:)
DebugLogEntry.capture(
category: "rule_run",
level: "error",
message: "Rule run failed: #{error.class}: #{error.message}",
source: source,
family: rule.family,
metadata: {
rule_run_id: id,
rule_id: rule_id,
rule_name: rule_name,
execution_type: execution_type,
error_class: error.class.name,
error_message: error.message,
transaction_count: transaction_ids.size,
transaction_ids: transaction_ids,
backtrace: Array(error.backtrace).first(10)
}
)
end
end