flexmeasures.data.services.job_rerun

Deciding who may re-run a failed background job, and re-running it.

Functions

flexmeasures.data.services.job_rerun.can_rerun_job(job: Job, status: JobStatus | str | None = None) → bool

Whether the current user may re-run this job now, so that the UI only offers it when it would work.

flexmeasures.data.services.job_rerun.check_job_rerun_access(job: Job) → GenericAsset

Require that the current user may re-run this job, and return the asset to log the re-run on.

The permission follows the type of job, as it does when triggering one: trigger-schedules for schedules, trigger-forecasts for forecasts, and trigger-reports for reports.

Raises:
  • JobNotRerunnable – if the job is of an unknown type, or names no asset or sensor.

  • Forbidden – if the current user may not re-run it.

flexmeasures.data.services.job_rerun.rerun_failed_job(job: Job) → None

Queue a failed job again, under the same job ID.

Keeping the ID keeps the job indexed under its assets and sensors, and keeps its dependents attached.

Raises:

JobNotFailed – if the job has not failed, or is no longer in the queue’s registry of failed jobs.

Exceptions

exception flexmeasures.data.services.job_rerun.JobNotFailed

Only a failed job can be re-run.

exception flexmeasures.data.services.job_rerun.JobNotRerunnable

The job cannot be re-run from the API, whoever asks.