Recovery

class chancy.plugins.recovery.Recovery(*, poll_interval: int = 60)[source]

Bases: Plugin

Recovers jobs that appear to be abandoned by a worker.

Typically, this happens when a worker is unexpectedly terminated, or has otherwise been lost which we recognize by checking the last seen timestamp of the worker heartbeat.

This will transition any matching jobs back to the “pending” state, and increment the max_attempts counter by 1 to allow it to be retried.

Parameters:

poll_interval – The number of seconds between recovery poll intervals.

classmethod get_scope() PluginScope[source]

Get the scope of this plugin. Scopes control when and where the plugin will be run.

By default, plugins are scoped to the worker.

async classmethod recover(worker: Worker, chancy: Chancy, cursor: AsyncCursor) int[source]

Recover jobs that were running when the worker was unexpectedly terminated, or has otherwise been lost.

Parameters:
  • worker – The worker that is running the recovery.

  • chancy – The Chancy application.

  • cursor – The cursor to use for database operations.

Returns:

The number of rows recovered from the database

async run(worker: Worker, chancy: Chancy)[source]

Runs the plugin.

This function can and should run indefinitely, as it will be cancelled when the worker is stopped.