Error handling
Dispatch retries the execution of a function whenever a failure occurs, whether it’s an exception, a loss of connection or power outage. However, not all failures are the same, so you might want to teach Dispatch how to handle exceptions specific to your application.
Temporary errors
When error is temporary, tell Dispatch that it’s safe to retry that function until it succeeds. For example, when application is in maintenance mode, tell Dispatch to retry the function until application is back up again.
register_error_type
function tells Dispatch that whenever MaintenanceException
occurs, treat it as a temporary error and retry.
Permanent errors
When error is fatal, retrying doesn’t make sense, because the function will keep running into it.
Dispatch stops retrying a function when it returns a PERMANENT_ERROR
status.
For example, the user we wanted to send email to is now deactivated.
Retrying on success
There are also cases when a function has successfully completed, but you may still want to retry it.
For example, a hosting provider that waits for a user to add a DNS record, so they can connect their domain to a website.
When Dispatch notices a DNSVerification
instance as a return value, confirm_dns_records_presence
is executed to tell Dispatch what it should do next — retry later or complete execution.
If user hasn’t added DNS records yet, Dispatch will keep retrying wait_for_dns_records
function. When DNS records show up, connect_domain
will resume execution and mark domain as connected.
Status reference
Status | Description | Behavior |
---|---|---|
Status.OK | Function executed successfully | Done. |
Status.TEMPORARY_ERROR | Temporary error occurred | Retry function later. |
Status.PERMANENT_ERROR | Temporary error occurred | Retry function later. |
Status.TIMEOUT | Operation took too long. | Retry function later. |
Status.INVALID_ARGUMENT | Invalid input. | Fatal error, don’t retry. |
Status.DNS_ERROR | TODO | TODO |
Status.TCP_ERROR | TODO | TODO |
Status.TLS_ERROR | TODO | TODO |
Status.HTTP_ERROR | TODO | TODO |
Status.UNAUTHENTICATED | TODO | TODO |
Status.PERMISSION_DENIED | TODO | TODO |
Status.NOT_FOUND | TODO | TODO |
Status.INVALID_RESPONSE | TODO | TODO |
Status.INCOMPATIBLE_STATE | TODO | TODO |