Exponential backoff

Summary

Tries and retries down-stream functions until a success event is emitted. The delay between successive attempts increase exponentially.

Exponential backoff is useful when executing a task that may fail and would like to retry in a cooperative manner.

For example:

The only functionality inSignal Success is emitting a success event.

exports.handler = async(ev, ctx) => {
  ctx.emit('success', {});
};

Ports

Each time an event is received on the in port, one exponential backoff session is created. The received event is immediately re-emitted on out. The received event is then re-emitted according to the parameters set in Settings -> Parameters.

Multiple backoff sessions may be in progress at the same time and do not interfer with each other.

Input/Output Format

The function accepts any value as an input on the in port. The received event is passed through without any modifications to the out port.

Events

The function registers a once listener for a 'success' event. The listener lives for the duration of one attempt, e.g. the listener for the first attempt is active until the second attempt starts.

A success event is used to signal to this function that the downstream function has succeded and no more retries are necessary.

The event data is not utilised, and thus may any data be sent along with the event.

Other

A maximum number of attempts can be specified in Settings -> Parameters. If specified, no more attempts are performed than the specified limit. This means that the attempts may end without a success event ever being emitted. If no limit is specified, the number of attempts is unlimited.