Reprioritization

class chancy.plugins.reprioritize.Reprioritize(rule, *, check_interval: int = 300, priority_increase: int = 1, batch_size: int = 1000)[source]

Bases: Plugin

A plugin that increases the priority of jobs based on how long they’ve been in the queue. This helps prevent job starvation by gradually increasing the priority of older jobs.

Example usage:

plugin = Reprioritize(
    rule=(
        (Reprioritize.Rules.Age() > 600) &
        (Reprioritize.Rules.Queue() == "high-priority")
    ),
    check_interval=300,
    priority_increase=1
)

This means that any job that has been in the queue for more than 10 minutes will have its priority increased by 1 every 5 minutes, but only for jobs in the high-priority queue.

Rules[source]

alias of JobRules

static get_dependencies() list[str][source]

Get the identifiers of all plugins this plugin depends on, if any.

Plugins that depend on the presence of other plugins will refuse to start if those dependencies are not met.

static get_identifier() str[source]

Returns a unique identifier for this plugin.

This identifier should be unique across all active plugins. If a custom plugin provides compatible functionality to a built-in plugin, it may use the same identifier as the built-in plugin.

async reprioritize_jobs(chancy) int[source]

Reprioritize jobs based on the rules provided to the plugin.

Returns the total number of jobs that were updated.

async run(worker, chancy)[source]

Runs the plugin.

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