gen_errand

gen_errand is a behavior module to simplify interaction with unreliable external services.

The primary use case is fetching resources, eg a connection to a remote database which may be temporarily down or overloaded: while the first connection attempt may fail, it may succeed when retried at a later time. It is not limited to resource fetching tasks, however, in fact most use cases that need some form of retrying can be modeled, like posting a message to your favorite social network and retrying if it happens to be down.

gen_errand relieves users of the burden of implementing retry and backoff logic over and over again, and to focus on the actual interaction logic instead.

Internals

Under the hood, gen_errand is a simplified state machine, with only four possible states:

Callbacks

Instructions

The handle_execute/1 and handle_event/4 callbacks must return an instruction or instruction tuple to tell the errand how to proceed.

Perform

This instruction is only allowed when the errand is in the idle state.

Idle

Continue

Stop

Done

Repeat

Retry

API functions

Convenience functions

Usage

See the examples directory for examples how gen_errand can be implemented and used.

Authors