diff --git a/README.md b/README.md index 574f310..4c24e10 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,8 @@ The creation API will return the task object: "total_size": 0, "largest_file": null, "largest_file_size": null, + "is_downloading": False, + "current_progessing_stage": "waiting_assign", "done": false, "failed": false, "recoverable": false, diff --git a/task/models.py b/task/models.py index ea13f93..34dd947 100644 --- a/task/models.py +++ b/task/models.py @@ -286,14 +286,17 @@ def get_current_step(self): return name @property - def current_step(self): + def current_progressing_stage(self) -> str: return self.get_current_step() @property - def is_downloading(self): - return self.current_step == "downloading_files" + def is_downloading(self) -> bool: + return self.current_progressing_stage in [ + "downloading_files", + "downloading_samplings", + ] - def get_resume_method_name(self): + def get_resume_method_name(self) -> str: resume_methods = { "waiting_assign": "restart", "transferring": "restart", @@ -304,11 +307,11 @@ def get_resume_method_name(self): if step_name: return resume_methods[step_name] - def inc_retry_times(self): + def inc_retry_times(self) -> None: self.retry_times += 1 self.save() - def schedule_resume(self): + def schedule_resume(self) -> None: if not self.failed: return method_name = self.get_resume_method_name() @@ -317,12 +320,12 @@ def schedule_resume(self): method() @classmethod - def schedule_resume_failed(cls): + def schedule_resume_failed(cls) -> None: for task in cls.filter_failed(): task.schedule_resume() @property - def done(self): + def done(self) -> bool: if self.failed: return False if not self.full_downloaded_at: @@ -332,7 +335,7 @@ def done(self): return True @property - def recoverable(self): + def recoverable(self) -> bool: if not self.failed: return False diff --git a/task/serializers.py b/task/serializers.py index 11d4629..b918a7c 100644 --- a/task/serializers.py +++ b/task/serializers.py @@ -29,6 +29,8 @@ class Meta: "total_size", "largest_file", "largest_file_size", + "is_downloading", + "current_progressing_stage", "done", "failed", "recoverable", diff --git a/task/tests/test_api.py b/task/tests/test_api.py index 794aa18..b17fc10 100644 --- a/task/tests/test_api.py +++ b/task/tests/test_api.py @@ -68,7 +68,42 @@ def test_create_task(self): self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(Task.objects.count(), 2) - assert response.json()["full_download_now"] is False + data = response.json() + assert data["full_download_now"] is False + assert data["current_progressing_stage"] == "waiting_assign" + assert data["is_downloading"] is False + assert set(data.keys()) == { + "callback", + "captcha_required", + "captcha_url", + "captcha", + "created_at", + "current_progressing_stage", + "done", + "failed", + "file_listed_at", + "finished_at", + "full_download_now", + "full_downloaded_at", + "id", + "is_downloading", + "largest_file_size", + "largest_file", + "message", + "path", + "recoverable", + "retry_times", + "sample_downloaded_at", + "sample_path", + "shared_id", + "shared_link", + "shared_password", + "started_at", + "status", + "total_files", + "total_size", + "transfer_completed_at", + } def test_create_task_full_download_now(self): url = reverse("task-list")