s365b.jobs.runner ================= .. py:module:: s365b.jobs.runner .. autoapi-nested-parse:: Running backup jobs. :class:`JobRunner` contains the logic; :mod:`s365b.jobs.tasks` only wraps it in Procrastinate tasks. Keeping them apart lets tests run jobs directly. Attributes ---------- .. autoapisummary:: s365b.jobs.runner.log Exceptions ---------- .. autoapisummary:: s365b.jobs.runner.JobSetupError Classes ------- .. autoapisummary:: s365b.jobs.runner.JobRunner Functions --------- .. autoapisummary:: s365b.jobs.runner.selected s365b.jobs.runner.is_due s365b.jobs.runner.copies_warning s365b.jobs.runner.discover_objects Module Contents --------------- .. py:data:: log .. py:exception:: JobSetupError Bases: :py:obj:`Exception` A job cannot start (no tenant connected, repository missing…). .. py:function:: selected(rows: list[s365b.db.models.ProtectedObjectRow], rules: dict[str, Any] | None) -> list[s365b.db.models.ProtectedObjectRow] Apply a job's include/exclude rules for one module. Rules: ``{"include": "all" | [external_id, ...], "exclude": [external_id, ...]}``. No rules means everything. :param rows: Discovered objects. :param rules: The module's selection rules from the job. :returns: The objects to back up. .. py:function:: is_due(schedule: str, at: datetime.datetime) -> bool Return whether a cron schedule fires at the given minute. :param schedule: Cron expression, e.g. ``"0 22 * * *"``. :param at: The minute to test. :returns: True if the schedule matches. .. py:function:: copies_warning(missing: int, error: str | None) -> str The warning for items without a restore copy (an extra copy). :param missing: Current items without the copy. :param error: Why the last attempt stopped, if it failed. :returns: A sentence for the run details and the alert email. .. py:class:: JobRunner(services: s365b.core.services.Services) Executes backup jobs. :param services: Process services. .. py:attribute:: progress_interval :value: 3.0 .. py:attribute:: services .. py:method:: run_backup_job(job_id: int, *, requested_by: str = 'scheduler') -> int :async: Run one backup job to completion. Never raises for problems inside the job: they are recorded on the job run and as events. :param job_id: Backup job ID. :param requested_by: Who started it (``scheduler`` or a username). :returns: The job run ID. .. py:method:: check_permissions(job: s365b.db.models.BackupJob, app: s365b.db.models.AppRegistration, enabled: dict[str, dict[str, Any]]) -> None Fail early if the Backup app lacks permissions the job's modules need. Without this every protected object fails with the same 403. :param job: The job. :param app: The Backup app registration. :param enabled: Raw configs of the enabled modules. :raises JobSetupError: Naming the missing permissions and the fix. .. py:method:: due_jobs(at: datetime.datetime) -> list[int] :async: Return the IDs of enabled jobs whose schedule fires at ``at``. :param at: The minute being scheduled (server time zone). :returns: Job IDs. .. py:function:: discover_objects(services: s365b.core.services.Services, module_id: str) -> list[s365b.db.models.ProtectedObjectRow] :async: Discover a module's objects in the tenant now and update the catalog. :param services: Process services. :param module_id: The module. :returns: The discovered objects. :raises JobSetupError: If no tenant or Backup app is set up.