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