API reference
This is a quick overview of the API surface you’d be interacting with most of the time. There’s also a full API reference available.
dispatch.function
Function decorator that makes any function resumable.
Wrapped function has a dispatch
method to invoke it.
dispatch.batch
Execute multiple functions in parallel, without waiting for their completion.
dispatch.gather
Execute multiple functions in parallel, wait for their completion and return their results.
dispatch.run
Run the HTTP server for communication between your application and Dispatch. It takes an optional function argument, which is called when initializion has completed.
dispatch.run
must be used together with our CLI, which sets up the necessary configuration for dispatch.run
to successfully connect to Dispatch.
dispatch.register_error_type
Register a handler for an exception.
Handler function is expected to return a Status
, which determines Dispatch behavior.
dispatch.register_output_type
Register a handler for resumable function’s return value upon completion. It’s useful in case function executes successfully, but you might still want to retry it later. Note that for handler to be executed, your resumable function must return a class instance.
Status
Status
enum is expected to be returned from handlers registered with dispatch.register_error_type
or dispatch.register_output_type
.
Each status instructs Dispatch whether to retry executing a resumable function or not.
In addition to retries, status can impact the concurrency rate at which Dispatch executes your resumable function.
For example, when status indicates an error, concurrency rate is decreased to reduce the load on your system.
When status indicates success, concurrency rate is increased.
Status.OK
Retry: No.
Concurrency: Increase.
Function completed successfully.
Status.TEMPORARY_ERROR
Retry: Yes.
Concurrency: Decrease.
Function encountered a temporary error that may resolve soon.
Status.PERMANENT_ERROR
Retry: No.
Concurrency: Increase.
Function encountered a permanent error.
Status.TIMEOUT
Retry: Yes.
Concurrency: Decrease.
Function encountered a timeout.
Status.THROTTLED
Retry: Yes.
Concurrency: Decrease.
Function was throttled.
Status.UNAUTHENTICATED
Retry: No.
Concurrency: Increase.
Function attempted to perform an operation without authentication.
Status.PERMISSION_DENIED
Retry: No.
Concurrency: Increase.
Function attempted to perform an operation without permission.
Status.NOT_FOUND
Retry: No.
Concurrency: Increase.
FUnction attempted to access a non-existent resource.
Status.INVALID_ARGUMENT
Retry: No.
Concurrency: Increase.
Function was provided invalid input.
Status.INVALID_RESPONSE
Retry: No.
Concurrency: Increase.
Function encountered an unexpected response from other part of the system.
Status.DNS_ERROR
Retry: Yes.
Concurrency: Decrease.
Function encountered a DNS error.
Status.TCP_ERROR
Retry: Yes.
Concurrency: Decrease.
Function encountered a TCP error.
Status.TLS_ERROR
Retry: Yes.
Concurrency: Decrease.
Function encountered a TLS error.
Status.HTTP_ERROR
Retry: Yes.
Concurrency: Decrease.
Function encountered an HTTP error.
Status.UNSPECIFIED
Retry: No.
Concurrency: Increase.
A generic default status.