27 lines
725 B
Python
27 lines
725 B
Python
|
from app.extensions import db
|
||
|
from app.models.task import Task
|
||
|
|
||
|
def success_state(task_id):
|
||
|
task = Task.query.filter_by(task_id=task_id).one()
|
||
|
|
||
|
task.status = "SUCCESS"
|
||
|
task.status_message = "Задача выполнена успешно"
|
||
|
|
||
|
db.session.commit()
|
||
|
|
||
|
def failure_state(task_id, exception):
|
||
|
task = Task.query.filter_by(task_id=task_id).one()
|
||
|
|
||
|
task.status = "FAILURE"
|
||
|
task.status_message = f"Произошла ошибка: {str(exception)}"
|
||
|
|
||
|
db.session.commit()
|
||
|
|
||
|
def run_state(task_id, task_record_id):
|
||
|
task = Task.query.get(task_record_id)
|
||
|
|
||
|
task.task_id = task_id
|
||
|
task.status = "RUNNING"
|
||
|
task.status_message = "Задача запущена"
|
||
|
|
||
|
db.session.commit()
|