s365b.jobs.tasks

Procrastinate tasks and the worker app.

There is no separate scheduler process: Procrastinate workers run periodic tasks themselves, and a database lock makes sure each tick runs once even with several workers. Every minute, scheduler_tick() queues the backup jobs whose cron schedule is due.

Attributes

Functions

services() → s365b.core.services.Services

Return this worker's services, created on first use.

run_backup_job(job_id[, requested_by]) → int

Run a backup job (queued by the scheduler or the UI).

run_restore(run_id) → int

Run a restore queued from Browse.

scheduler_tick(timestamp) → list[int]

Queue backup jobs whose schedule is due this minute.

run_retention(repository_id[, requested_by, attempt]) → int

Apply a repository's retention policy (nightly, or from the UI).

retention_tick(timestamp) → list[int]

At the configured hour, queue retention for every repository.

deliver_notifications(timestamp) → dict[str, int]

Email the events that are due (every minute).

build_app(settings) → procrastinate.App

Return the Procrastinate app for this database (one per process).

Module Contents

s365b.jobs.tasks.log[source]
s365b.jobs.tasks.tasks[source]
s365b.jobs.tasks.services() → s365b.core.services.Services[source]

Return this worker’s services, created on first use.

Returns:

The services.

async s365b.jobs.tasks.run_backup_job(job_id: int, requested_by: str = 'scheduler') → int[source]

Run a backup job (queued by the scheduler or the UI).

Parameters:
  • job_id – Backup job ID.

  • requested_by – Who started it.

Returns:

The job run ID.

async s365b.jobs.tasks.run_restore(run_id: int) → int[source]

Run a restore queued from Browse.

Parameters:

run_id – The queued job run.

Returns:

The job run ID.

async s365b.jobs.tasks.scheduler_tick(timestamp: int) → list[int][source]

Queue backup jobs whose schedule is due this minute.

A queueing lock per job prevents a second run from being queued while one is still waiting.

Parameters:

timestamp – The scheduled minute (Unix time), from Procrastinate.

Returns:

IDs of jobs queued.

s365b.jobs.tasks.RETENTION_RETRY_MINUTES = 30[source]
s365b.jobs.tasks.RETENTION_MAX_ATTEMPTS = 12[source]
async s365b.jobs.tasks.run_retention(repository_id: int, requested_by: str = 'scheduler', attempt: int = 1) → int[source]

Apply a repository’s retention policy (nightly, or from the UI).

If a backup is writing to the repository, the run is recorded as skipped and retried 30 minutes later.

Parameters:
  • repository_id – Repository row ID.

  • requested_by – Who started it.

  • attempt – Retry counter.

Returns:

The job run ID.

async s365b.jobs.tasks.retention_tick(timestamp: int) → list[int][source]

At the configured hour, queue retention for every repository.

Also deletes audit log entries and alerts past their retention.

Parameters:

timestamp – The scheduled hour (Unix time), from Procrastinate.

Returns:

IDs of repositories queued.

async s365b.jobs.tasks.deliver_notifications(timestamp: int) → dict[str, int][source]

Email the events that are due (every minute).

Parameters:

timestamp – The scheduled minute (Unix time), from Procrastinate.

Returns:

Count of events per outcome.

s365b.jobs.tasks.build_app(settings: s365b.core.config.Settings) → procrastinate.App[source]

Return the Procrastinate app for this database (one per process).

add_tasks_from renames the blueprint’s tasks in place, so building a second app would turn s365b:run_backup_job into s365b:s365b:run_backup_job, a task no worker knows. The app is therefore built once and reused.

Parameters:

settings – Process settings.

Returns:

The app (open it with open_async before use).