From b8d02231cf65b813878c3cb3e313a0a922bcb9fc Mon Sep 17 00:00:00 2001 From: Houkime <> Date: Wed, 3 Jan 2024 15:46:48 +0000 Subject: [PATCH] fix(services): handle the async nature of moving. --- .../graphql/mutations/services_mutations.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/selfprivacy_api/graphql/mutations/services_mutations.py b/selfprivacy_api/graphql/mutations/services_mutations.py index ad3b1b9..9bacf66 100644 --- a/selfprivacy_api/graphql/mutations/services_mutations.py +++ b/selfprivacy_api/graphql/mutations/services_mutations.py @@ -160,6 +160,8 @@ class ServicesMutations: message="Service not found.", code=404, ) + # TODO: make serviceImmovable and BlockdeviceNotFound exceptions + # in the move_to_volume() function and handle them here if not service.is_movable(): return ServiceJobMutationReturn( success=False, @@ -176,7 +178,15 @@ class ServicesMutations: service=service_to_graphql_service(service), ) job = service.move_to_volume(volume) - if job.status == JobStatus.FINISHED: + if job.status in [JobStatus.CREATED, JobStatus.RUNNING]: + return ServiceJobMutationReturn( + success=True, + message="Started moving the service.", + code=200, + service=service_to_graphql_service(service), + job=job_to_api_job(job), + ) + elif job.status == JobStatus.FINISHED: return ServiceJobMutationReturn( success=True, message="Service moved.",