add retry count to task (#2152)

### What problem does this PR solve?


### Type of change

- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
Kevin Hu
2024-08-29 13:31:41 +08:00
committed by GitHub
parent 06abef66ef
commit 212bb8e601
2 changed files with 21 additions and 2 deletions

View File

@ -64,9 +64,20 @@ class TaskService(CommonService):
docs = list(docs.dicts())
if not docs: return []
cls.model.update(progress_msg=cls.model.progress_msg + "\n" + "Task has been received.",
progress=random.random() / 10.).where(
msg = "\nTask has been received."
prog = random.random() / 10.
if docs[0]["retry_count"] >= 3:
msg = "\nERROR: Task is abandoned after 3 times attempts."
prog = -1
cls.model.update(progress_msg=cls.model.progress_msg + msg,
progress=prog,
retry_count=docs[0]["retry_count"]+1
).where(
cls.model.id == docs[0]["id"]).execute()
if docs[0]["retry_count"] >= 3: return []
return docs
@classmethod