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.
To treat an error as temporary, implement an interface { Temporary() bool }
interface for that error.
When Temporary
method of an error returns true
, Dispatch treats it as a temporary error and retries the function that returns it.
In the example above, the notifyUser
function is in maintanence mode for the first two calls and succeeds on the third one.
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 error’s Temporary
method returns true
.
For example, the user we wanted to send email to is now deactivated.
Built-in Go errors
Dispatch recognizes the most common Go errors out of the box and determines whether it’s safe to retry the function call.