s365b.jobs.tasks ================ .. py:module:: s365b.jobs.tasks .. autoapi-nested-parse:: 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, :func:`scheduler_tick` queues the backup jobs whose cron schedule is due. Attributes ---------- .. autoapisummary:: s365b.jobs.tasks.log s365b.jobs.tasks.tasks s365b.jobs.tasks.RETENTION_RETRY_MINUTES s365b.jobs.tasks.RETENTION_MAX_ATTEMPTS Functions --------- .. autoapisummary:: s365b.jobs.tasks.services s365b.jobs.tasks.run_backup_job s365b.jobs.tasks.run_restore s365b.jobs.tasks.scheduler_tick s365b.jobs.tasks.run_retention s365b.jobs.tasks.retention_tick s365b.jobs.tasks.deliver_notifications s365b.jobs.tasks.build_app Module Contents --------------- .. py:data:: log .. py:data:: tasks .. py:function:: services() -> s365b.core.services.Services Return this worker's services, created on first use. :returns: The services. .. py:function:: run_backup_job(job_id: int, requested_by: str = 'scheduler') -> int :async: Run a backup job (queued by the scheduler or the UI). :param job_id: Backup job ID. :param requested_by: Who started it. :returns: The job run ID. .. py:function:: run_restore(run_id: int) -> int :async: Run a restore queued from Browse. :param run_id: The queued job run. :returns: The job run ID. .. py:function:: scheduler_tick(timestamp: int) -> list[int] :async: 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. :param timestamp: The scheduled minute (Unix time), from Procrastinate. :returns: IDs of jobs queued. .. py:data:: RETENTION_RETRY_MINUTES :value: 30 .. py:data:: RETENTION_MAX_ATTEMPTS :value: 12 .. py:function:: run_retention(repository_id: int, requested_by: str = 'scheduler', attempt: int = 1) -> int :async: 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. :param repository_id: Repository row ID. :param requested_by: Who started it. :param attempt: Retry counter. :returns: The job run ID. .. py:function:: retention_tick(timestamp: int) -> list[int] :async: At the configured hour, queue retention for every repository. Also deletes audit log entries and alerts past their retention. :param timestamp: The scheduled hour (Unix time), from Procrastinate. :returns: IDs of repositories queued. .. py:function:: deliver_notifications(timestamp: int) -> dict[str, int] :async: Email the events that are due (every minute). :param timestamp: The scheduled minute (Unix time), from Procrastinate. :returns: Count of events per outcome. .. py:function:: build_app(settings: s365b.core.config.Settings) -> procrastinate.App 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. :param settings: Process settings. :returns: The app (open it with ``open_async`` before use).