Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add retry count to task #2152

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add retry count to task
  • Loading branch information
KevinHuSh committed Aug 29, 2024
commit 56c81e4ae75cc3324011654a482e1edf2628b6ef
8 changes: 8 additions & 0 deletions api/db/db_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ class Task(DataBaseModel):
null=True,
help_text="process message",
default="")
retry_count = IntegerField(default=0)


class Dialog(DataBaseModel):
Expand Down Expand Up @@ -982,3 +983,10 @@ def migrate_db():
DB.execute_sql('ALTER TABLE llm ADD PRIMARY KEY (llm_name,fid);')
except Exception as e:
pass
try:
migrate(
migrator.add_column('task', 'retry_count', IntegerField(default=0))
)
except Exception as e:
pass

15 changes: 13 additions & 2 deletions api/db/services/task_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,20 @@ def get_tasks(cls, task_id):
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
Expand Down