工作流重做方法

This commit is contained in:
Jerry Yan 2022-04-18 09:17:05 +08:00
parent be3f4d6519
commit ce3d65455d

View File

@ -1,6 +1,9 @@
import threading
from flask import Blueprint, jsonify
from model.Workflow import Workflow
from worker.danmaku import do_workflow
from model import db
blueprint = Blueprint("api_workflow", __name__, url_prefix="/api/workflow")
@ -18,15 +21,47 @@ def get_workflow_info(workflow_id):
return jsonify(workflow)
@blueprint.put("/<int:workflow_id>/done")
def done_editing(workflow_id):
@blueprint.post("/<int:workflow_id>/edit")
def start_editing(workflow_id):
workflow = Workflow.get(workflow_id)
if workflow is None:
response = jsonify({
"message": "Not Found"
})
response.status_code = 404
return response
workflow.editing = True
db.session.commit()
return jsonify(workflow.to_dict())
@blueprint.post("/<int:workflow_id>/queue")
def add_to_queue(workflow_id):
# JOB_QUEUE.put(workflow_item)
return jsonify({
'id': workflow_id,
})
@blueprint.delete("/<int:workflow_id>/edit")
def done_editing(workflow_id):
workflow = Workflow.get(workflow_id)
if workflow is None:
response = jsonify({
"message": "Not Found"
})
response.status_code = 404
return response
workflow.editing = False
db.session.commit()
return jsonify(workflow.to_dict())
@blueprint.post("/<int:workflow_id>/do")
def do_workflow(workflow_id):
workflow = Workflow.get(workflow_id)
if workflow is None:
response = jsonify({
"message": "Not Found"
})
response.status_code = 404
return response
if len(workflow.video_clips) > 0 and len(workflow.danmaku_clips) > 0:
threading.Thread(target=do_workflow, args=(
workflow.video_clips[0].full_path,
workflow.danmaku_clips[0].full_path,
*[clip.full_path for clip in workflow.danmaku_clips[1:]]
)).start()
return jsonify(workflow.to_dict())