0

我正在使用 Flask 在繁重的视频分析代码上构建 UI。我需要添加一个实现来停止后台任务。为此,我需要获取当前正在执行的作业 ID,然后停止它。

training.py - 

from myproject import r, q

@training.route('/projectdetails/training', methods=["GET", "POST"])
@login_required
def start_training():

    jobs = q.jobs
    message = None

    if request.args:
        # project_name = request.args.get('project')
        epoch = int(request.args.get('epoch'))

        input_videos_path = request.args.get('input_videos_path')
        checkpoints_path = request.args.get('checkpoints_path')

        video_name = request.args.get('video_name')
        video_format = request.args.get('video_format')
        video_size = request.args.get('video_size')

        task = q.enqueue(train_test, epoch, input_videos_path, checkpoints_path)
        jobs = q.jobs
        q_len = len(q)
        message = f"Task queued at {task.enqueued_at.strftime('%a %d %b %Y %H:%M:%S')}. {q_len} jobs queued."

我的 init 文件从 - 导入 redis 连接

import redis
from rq import Queue

# redis config
r = redis.Redis()
q = Queue(connection=r)

一切都运行良好,但我现在需要添加一个选项来停止当前正在运行的后台任务。

4

0 回答 0