mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-22 20:11:30 +00:00
feature(backups): simplest jobs intergration in tasks: created and finished
This commit is contained in:
parent
4572c00640
commit
fa86c45bd0
31
selfprivacy_api/backup/jobs.py
Normal file
31
selfprivacy_api/backup/jobs.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from selfprivacy_api.jobs import Jobs, Job, JobStatus
|
||||||
|
from selfprivacy_api.services.service import Service
|
||||||
|
|
||||||
|
|
||||||
|
def backup_job_type(service: Service):
|
||||||
|
return f"services.{service.get_id()}.backup"
|
||||||
|
|
||||||
|
|
||||||
|
def add_backup_job(service: Service) -> Job:
|
||||||
|
display_name = service.get_display_name()
|
||||||
|
job = Jobs.add(
|
||||||
|
type_id=backup_job_type(service),
|
||||||
|
name=f"Backup {display_name}",
|
||||||
|
description=f"Backing up {display_name}",
|
||||||
|
)
|
||||||
|
return job
|
||||||
|
|
||||||
|
|
||||||
|
def get_job_by_type(type_id: str) -> Optional[Job]:
|
||||||
|
for job in Jobs.get_jobs():
|
||||||
|
if job.type_id == type_id and job.status in [
|
||||||
|
JobStatus.CREATED,
|
||||||
|
JobStatus.RUNNING,
|
||||||
|
]:
|
||||||
|
return job
|
||||||
|
|
||||||
|
|
||||||
|
def get_backup_job(service: Service) -> Optional[Job]:
|
||||||
|
return get_job_by_type(backup_job_type(service))
|
|
@ -4,6 +4,8 @@ from selfprivacy_api.models.backup.snapshot import Snapshot
|
||||||
from selfprivacy_api.utils.huey import huey
|
from selfprivacy_api.utils.huey import huey
|
||||||
from selfprivacy_api.services.service import Service
|
from selfprivacy_api.services.service import Service
|
||||||
from selfprivacy_api.backup import Backups
|
from selfprivacy_api.backup import Backups
|
||||||
|
from selfprivacy_api.backup.jobs import get_backup_job, add_backup_job
|
||||||
|
from selfprivacy_api.jobs import Jobs, JobStatus
|
||||||
|
|
||||||
|
|
||||||
def validate_datetime(dt: datetime):
|
def validate_datetime(dt: datetime):
|
||||||
|
@ -21,7 +23,10 @@ def validate_datetime(dt: datetime):
|
||||||
# huey tasks need to return something
|
# huey tasks need to return something
|
||||||
@huey.task()
|
@huey.task()
|
||||||
def start_backup(service: Service) -> bool:
|
def start_backup(service: Service) -> bool:
|
||||||
|
add_backup_job(service)
|
||||||
Backups.back_up(service)
|
Backups.back_up(service)
|
||||||
|
job = get_backup_job(service)
|
||||||
|
Jobs.update(job, status=JobStatus.FINISHED)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue