mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-02-02 14:16:38 +00:00
fix(backup): do not store maybe unpicklable service on the queue
This commit is contained in:
parent
aa287d9cf3
commit
267cdd391b
|
@ -11,7 +11,9 @@ from selfprivacy_api.graphql.common_types.backup import (
|
|||
from selfprivacy_api.models.backup.snapshot import Snapshot
|
||||
from selfprivacy_api.utils.huey import huey
|
||||
from huey import crontab
|
||||
|
||||
from selfprivacy_api.services.service import Service
|
||||
from selfprivacy_api.services import get_service_by_id
|
||||
from selfprivacy_api.backup import Backups
|
||||
from selfprivacy_api.jobs import Jobs, JobStatus, Job
|
||||
|
||||
|
@ -34,11 +36,14 @@ def validate_datetime(dt: datetime) -> bool:
|
|||
# huey tasks need to return something
|
||||
@huey.task()
|
||||
def start_backup(
|
||||
service: Service, reason: BackupReason = BackupReason.EXPLICIT
|
||||
service_id: str, reason: BackupReason = BackupReason.EXPLICIT
|
||||
) -> bool:
|
||||
"""
|
||||
The worker task that starts the backup process.
|
||||
"""
|
||||
service = get_service_by_id(service_id)
|
||||
if service is None:
|
||||
raise ValueError(f"No such service: {service_id}")
|
||||
Backups.back_up(service, reason)
|
||||
return True
|
||||
|
||||
|
|
|
@ -148,7 +148,7 @@ class BackupMutations:
|
|||
)
|
||||
|
||||
job = add_backup_job(service)
|
||||
start_backup(service)
|
||||
start_backup(service_id)
|
||||
|
||||
return GenericJobMutationReturn(
|
||||
success=True,
|
||||
|
|
|
@ -14,6 +14,8 @@ from selfprivacy_api.utils.huey import huey
|
|||
|
||||
import tempfile
|
||||
|
||||
from selfprivacy_api.utils.huey import huey
|
||||
|
||||
from tests.test_common import dummy_service, raw_dummy_service
|
||||
|
||||
from selfprivacy_api.services import Service, get_all_services
|
||||
|
@ -69,7 +71,15 @@ def backups_local(tmpdir):
|
|||
|
||||
@pytest.fixture(scope="function")
|
||||
def backups(tmpdir):
|
||||
# for those tests that are supposed to pass with any repo
|
||||
"""
|
||||
For those tests that are supposed to pass with
|
||||
both local and cloud repos
|
||||
"""
|
||||
|
||||
# Sometimes this is false. Idk why.
|
||||
huey.immediate = True
|
||||
assert huey.immediate is True
|
||||
|
||||
Backups.reset()
|
||||
if BACKUP_PROVIDER_ENVS["kind"] in os.environ.keys():
|
||||
Backups.set_provider_from_envs()
|
||||
|
@ -736,7 +746,7 @@ def simulated_service_stopping_delay(request) -> float:
|
|||
def test_backup_service_task(backups, dummy_service, simulated_service_stopping_delay):
|
||||
dummy_service.set_delay(simulated_service_stopping_delay)
|
||||
|
||||
handle = start_backup(dummy_service)
|
||||
handle = start_backup(dummy_service.get_id())
|
||||
handle(blocking=True)
|
||||
|
||||
snaps = Backups.get_snapshots(dummy_service)
|
||||
|
@ -781,7 +791,7 @@ def test_backup_larger_file(backups, dummy_service):
|
|||
mega = 2**20
|
||||
make_large_file(dir, 100 * mega)
|
||||
|
||||
handle = start_backup(dummy_service)
|
||||
handle = start_backup(dummy_service.get_id())
|
||||
handle(blocking=True)
|
||||
|
||||
# results will be slightly different on different machines. if someone has troubles with it on their machine, consider dropping this test.
|
||||
|
|
Loading…
Reference in a new issue