mirror of
https://github.com/we-promise/sure.git
synced 2026-09-05 23:01:26 +00:00
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:
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user