Simple Linux Panel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mdserver-web/web/admin/task/__init__.py

93 lines
2.8 KiB

7 months ago
# coding:utf-8
# ---------------------------------------------------------------------------------
# MW-Linux面板
# ---------------------------------------------------------------------------------
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved.
# ---------------------------------------------------------------------------------
# Author: midoks <midoks@163.com>
# ---------------------------------------------------------------------------------
6 months ago
import json
import time
7 months ago
from flask import Blueprint, render_template
6 months ago
from flask import request
6 months ago
from admin.user_login_check import panel_login_required
6 months ago
import core.mw as mw
6 months ago
import utils.task as MwTasks
6 months ago
import thisdb
7 months ago
blueprint = Blueprint('task', __name__, url_prefix='/task', template_folder='../../templates/default')
7 months ago
7 months ago
@blueprint.route('/count', endpoint='task_count')
6 months ago
@panel_login_required
7 months ago
def task_count():
6 months ago
return str(thisdb.getTaskUnexecutedCount())
6 months ago
@blueprint.route('/list', endpoint='list', methods=['POST'])
6 months ago
@panel_login_required
6 months ago
def list():
p = request.form.get('p', '1')
limit = request.form.get('limit', '10').strip()
search = request.form.get('search', '').strip()
6 months ago
return MwTasks.getTaskPage(int(p), int(limit))
6 months ago
@blueprint.route('/get_exec_log', endpoint='get_exec_log', methods=['POST'])
6 months ago
@panel_login_required
6 months ago
def get_exec_log():
file = mw.getPanelTaskLog()
return mw.getLastLine(file, 100)
@blueprint.route('/get_task_speed', endpoint='get_task_speed', methods=['POST'])
6 months ago
@panel_login_required
6 months ago
def get_task_speed():
6 months ago
count = thisdb.getTaskUnexecutedCount()
6 months ago
if count == 0:
return mw.returnData(False, '当前没有任务队列在执行-2!')
6 months ago
row = thisdb.getTaskFirstByRun()
6 months ago
if row is None:
return mw.returnData(False, '当前没有任务队列在执行-3!')
6 months ago
task_logfile = mw.getPanelTaskLog()
6 months ago
data = {}
data['name'] = row['name']
data['cmd'] = row['cmd']
if row['type'] == 'download':
6 months ago
readLine = ''
6 months ago
for i in range(3):
try:
readLine = mw.readFile(task_logfile)
6 months ago
data['msg'] = json.loads(readLine)
data['isDownload'] = True
6 months ago
except Exception as e:
if i == 2:
6 months ago
thisdb.setTaskStatus(row['id'],0)
return mw.returnData(False, '当前没有任务队列在执行-4:' + str(e))
6 months ago
time.sleep(0.5)
else:
data['msg'] = mw.getLastLine(task_logfile, 10)
data['isDownload'] = False
data['task'] = thisdb.getTaskRunList(1,6)
6 months ago
return data
6 months ago
@blueprint.route('/remove_task', endpoint='remove_task', methods=['POST'])
@panel_login_required
def remove_task():
task_id = request.form.get('id', '')
if task_id == '':
return mw.returnData(False, '任务ID不能为空!')
return MwTasks.removeTask(task_id)
6 months ago