PaperParser/app/blueprints/api/tasks/handlers.py

37 lines
804 B
Python
Raw Permalink Normal View History

2024-01-31 19:37:01 +10:00
from app.extensions import db
from app.models.task import Task
def success_state(task_id):
2024-02-08 18:00:37 +10:00
task = Task.query.get(task_id)
2024-01-31 19:37:01 +10:00
2024-04-12 20:17:51 +10:00
if not task:
return
2024-01-31 19:37:01 +10:00
task.status = "SUCCESS"
2024-02-08 18:00:37 +10:00
task.status_message = "задача выполнена успешно"
2024-03-13 18:48:52 +10:00
db.session.commit()
2024-01-31 19:37:01 +10:00
def failure_state(task_id, exception):
2024-02-08 18:00:37 +10:00
task = Task.query.get(task_id)
2024-01-31 19:37:01 +10:00
2024-04-12 20:17:51 +10:00
if not task:
return
2024-01-31 19:37:01 +10:00
task.status = "FAILURE"
2024-02-08 18:00:37 +10:00
task.status_message = f"произошла ошибка {str(exception)}"
2024-03-13 18:48:52 +10:00
db.session.commit()
2024-01-31 19:37:01 +10:00
def run_state(task_id, task_record_id):
task = Task.query.get(task_record_id)
2024-04-12 20:17:51 +10:00
if not task:
return
2024-01-31 19:37:01 +10:00
task.task_id = task_id
task.status = "RUNNING"
2024-03-13 18:48:52 +10:00
task.status_message = "задача запущена"
db.session.commit()