Status Reporting Methods
Why?
- Asynchronous execution supports event-driven workflows.
- The try-except block ensures errors are caught and reported.
- Explicit success/failure messages provide clarity.
Why?
- Uses Task for async execution to integrate with automation workflows.
- Ensures the function reports status before exiting.
- Encapsulates logic within try-catch to prevent silent failures.
Status Types and When to Use Them
Status | Method | When to Use |
---|---|---|
Success | mark_run_success() | Function executes correctly and returns expected results |
Failed | mark_run_failed() | Function completes but results are invalid or not useful |
Exception | mark_run_failed() + raise | Function crashes due to unexpected errors |
Why?
- Explicit status codes streamline debugging and monitoring.
- Differentiates between an expected failure and a catastrophic error.
- Enables structured logging for automated workflows.
Best Practices for Execution Reporting
-
Always Report Final Status
- Unreported failures leave automation in limbo.
-
Use Meaningful Messages
- Generic errors like “Process failed” are useless in debugging.
-
Choose the Right Status Type
- A function that runs but produces bad data should be marked as failed, not as an exception.
-
Include Relevant Metrics
- If processing a batch, report counts (e.g., “5 valid elements found”).
-
Handle All Error Cases
- Assume the worst: anticipate network failures, malformed data, and external system issues.