Skip to content

Commit

Permalink
clean up completion and failure exection metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
thedumbtechguy committed Dec 22, 2024
1 parent 5411059 commit dced860
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lib/chrono_forge/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ def perform(key, attempt: 0, options: {}, **kwargs)
nil
rescue => e
Rails.logger.error { "An error occurred during execution of #{key}" }
self.class::ExecutionTracker.track_error(workflow, e)
error_log = self.class::ExecutionTracker.track_error(workflow, e)

# Retry if applicable
if should_retry?(e, attempt)
self.class::RetryStrategy.schedule_retry(workflow, attempt: attempt)
else
fail_workflow! e
fail_workflow! error_log
end
ensure
context.save!
Expand All @@ -71,9 +71,6 @@ def complete_workflow!
step_name: "$workflow_completion$"
) do |log|
log.started_at = Time.current
log.metadata = {
workflow_id: workflow.id
}
end

begin
Expand Down Expand Up @@ -104,17 +101,15 @@ def complete_workflow!
end
end

def fail_workflow!(error)
def fail_workflow!(error_log)
# Create an execution log for workflow failure
execution_log = ExecutionLog.create_or_find_by!(
workflow: workflow,
step_name: "$workflow_failure$"
) do |log|
log.started_at = Time.current
log.metadata = {
workflow_id: workflow.id,
error_class: error.class.to_s,
error_message: error.message
error_log_id: error_log.id
}
end

Expand Down

0 comments on commit dced860

Please sign in to comment.