Skip to content

Commit 1a07fb5

Browse files
committed
feat(api): expose information of current processing stage and download status
1 parent 633db08 commit 1a07fb5

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ The creation API will return the task object:
5555
"total_size": 0,
5656
"largest_file": null,
5757
"largest_file_size": null,
58+
"is_downloading": False,
59+
"current_progessing_stage": "waiting_assign",
5860
"done": false,
5961
"failed": false,
6062
"recoverable": false,

task/models.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,17 @@ def get_current_step(self):
286286
return name
287287

288288
@property
289-
def current_step(self):
289+
def current_progressing_stage(self) -> str:
290290
return self.get_current_step()
291291

292292
@property
293-
def is_downloading(self):
294-
return self.current_step == "downloading_files"
293+
def is_downloading(self) -> bool:
294+
return self.current_progressing_stage in [
295+
"downloading_files",
296+
"downloading_samplings",
297+
]
295298

296-
def get_resume_method_name(self):
299+
def get_resume_method_name(self) -> str:
297300
resume_methods = {
298301
"waiting_assign": "restart",
299302
"transferring": "restart",
@@ -304,11 +307,11 @@ def get_resume_method_name(self):
304307
if step_name:
305308
return resume_methods[step_name]
306309

307-
def inc_retry_times(self):
310+
def inc_retry_times(self) -> None:
308311
self.retry_times += 1
309312
self.save()
310313

311-
def schedule_resume(self):
314+
def schedule_resume(self) -> None:
312315
if not self.failed:
313316
return
314317
method_name = self.get_resume_method_name()
@@ -317,12 +320,12 @@ def schedule_resume(self):
317320
method()
318321

319322
@classmethod
320-
def schedule_resume_failed(cls):
323+
def schedule_resume_failed(cls) -> None:
321324
for task in cls.filter_failed():
322325
task.schedule_resume()
323326

324327
@property
325-
def done(self):
328+
def done(self) -> bool:
326329
if self.failed:
327330
return False
328331
if not self.full_downloaded_at:
@@ -332,7 +335,7 @@ def done(self):
332335
return True
333336

334337
@property
335-
def recoverable(self):
338+
def recoverable(self) -> bool:
336339
if not self.failed:
337340
return False
338341

task/serializers.py

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class Meta:
2929
"total_size",
3030
"largest_file",
3131
"largest_file_size",
32+
"is_downloading",
33+
"current_progressing_stage",
3234
"done",
3335
"failed",
3436
"recoverable",

task/tests/test_api.py

+36-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,42 @@ def test_create_task(self):
6868

6969
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
7070
self.assertEqual(Task.objects.count(), 2)
71-
assert response.json()["full_download_now"] is False
71+
data = response.json()
72+
assert data["full_download_now"] is False
73+
assert data["current_progressing_stage"] == "waiting_assign"
74+
assert data["is_downloading"] is False
75+
assert set(data.keys()) == {
76+
"callback",
77+
"captcha_required",
78+
"captcha_url",
79+
"captcha",
80+
"created_at",
81+
"current_progressing_stage",
82+
"done",
83+
"failed",
84+
"file_listed_at",
85+
"finished_at",
86+
"full_download_now",
87+
"full_downloaded_at",
88+
"id",
89+
"is_downloading",
90+
"largest_file_size",
91+
"largest_file",
92+
"message",
93+
"path",
94+
"recoverable",
95+
"retry_times",
96+
"sample_downloaded_at",
97+
"sample_path",
98+
"shared_id",
99+
"shared_link",
100+
"shared_password",
101+
"started_at",
102+
"status",
103+
"total_files",
104+
"total_size",
105+
"transfer_completed_at",
106+
}
72107

73108
def test_create_task_full_download_now(self):
74109
url = reverse("task-list")

0 commit comments

Comments
 (0)