|
|
@@ -24,6 +24,17 @@ def set_xxl_executor(executor):
|
|
|
_executor_ref = executor
|
|
|
|
|
|
|
|
|
+async def _parse_body():
|
|
|
+ """解析请求体:优先 JSON,兜底 form-data
|
|
|
+
|
|
|
+ XXL-JOB Admin 不同版本发送方式不同(JSON 或 form),统一处理。
|
|
|
+ """
|
|
|
+ data = await request.get_json(silent=True)
|
|
|
+ if data:
|
|
|
+ return data
|
|
|
+ return await request.form
|
|
|
+
|
|
|
+
|
|
|
def create_xxl_bp() -> Blueprint:
|
|
|
"""创建 XXL-JOB API Blueprint
|
|
|
|
|
|
@@ -41,28 +52,28 @@ def create_xxl_bp() -> Blueprint:
|
|
|
@bp.route("/idleBeat", methods=["POST"])
|
|
|
async def idle_beat():
|
|
|
"""空闲检测:检查指定 jobId 是否正在运行"""
|
|
|
- form = await request.form
|
|
|
- job_id = int(form.get("jobId", 0))
|
|
|
+ body = await _parse_body()
|
|
|
+ job_id = int(body.get("jobId", 0))
|
|
|
result = _executor_ref.idle_beat(job_id)
|
|
|
return jsonify(result)
|
|
|
|
|
|
@bp.route("/run", methods=["POST"])
|
|
|
async def run():
|
|
|
"""触发任务执行"""
|
|
|
- form = await request.form
|
|
|
+ body = await _parse_body()
|
|
|
trigger_params = {
|
|
|
- "jobId": int(form.get("jobId", 0)),
|
|
|
- "executorHandler": form.get("executorHandler", ""),
|
|
|
- "executorParams": form.get("executorParams", ""),
|
|
|
- "executorBlockStrategy": form.get("executorBlockStrategy", ""),
|
|
|
- "executorTimeout": int(form.get("executorTimeout", 0)),
|
|
|
- "logId": int(form.get("logId", 0)),
|
|
|
- "logDateTime": int(form.get("logDateTime", 0)),
|
|
|
- "glueType": form.get("glueType", ""),
|
|
|
- "glueSource": form.get("glueSource", ""),
|
|
|
- "glueUpdatetime": int(form.get("glueUpdatetime", 0)),
|
|
|
- "broadcastIndex": int(form.get("broadcastIndex", 0)),
|
|
|
- "broadcastTotal": int(form.get("broadcastTotal", 1)),
|
|
|
+ "jobId": int(body.get("jobId", 0)),
|
|
|
+ "executorHandler": body.get("executorHandler", ""),
|
|
|
+ "executorParams": body.get("executorParams", ""),
|
|
|
+ "executorBlockStrategy": body.get("executorBlockStrategy", ""),
|
|
|
+ "executorTimeout": int(body.get("executorTimeout", 0)),
|
|
|
+ "logId": int(body.get("logId", 0)),
|
|
|
+ "logDateTime": int(body.get("logDateTime", 0)),
|
|
|
+ "glueType": body.get("glueType", ""),
|
|
|
+ "glueSource": body.get("glueSource", ""),
|
|
|
+ "glueUpdatetime": int(body.get("glueUpdatetime", 0)),
|
|
|
+ "broadcastIndex": int(body.get("broadcastIndex", 0)),
|
|
|
+ "broadcastTotal": int(body.get("broadcastTotal", 1)),
|
|
|
}
|
|
|
logger.info(
|
|
|
"XXL-JOB run: handler=%s, jobId=%s, params=%s",
|
|
|
@@ -76,8 +87,8 @@ def create_xxl_bp() -> Blueprint:
|
|
|
@bp.route("/kill", methods=["POST"])
|
|
|
async def kill():
|
|
|
"""强制终止任务"""
|
|
|
- form = await request.form
|
|
|
- job_id = int(form.get("jobId", 0))
|
|
|
+ body = await _parse_body()
|
|
|
+ job_id = int(body.get("jobId", 0))
|
|
|
logger.info("XXL-JOB kill: jobId=%s", job_id)
|
|
|
result = await _executor_ref.kill(job_id)
|
|
|
return jsonify(result)
|
|
|
@@ -85,10 +96,10 @@ def create_xxl_bp() -> Blueprint:
|
|
|
@bp.route("/log", methods=["POST"])
|
|
|
async def log():
|
|
|
"""读取执行日志"""
|
|
|
- form = await request.form
|
|
|
- log_date_time = int(form.get("logDateTim", 0))
|
|
|
- log_id = int(form.get("logId", 0))
|
|
|
- from_line_num = int(form.get("fromLineNum", 1))
|
|
|
+ body = await _parse_body()
|
|
|
+ log_date_time = int(body.get("logDateTim", 0))
|
|
|
+ log_id = int(body.get("logId", 0))
|
|
|
+ from_line_num = int(body.get("fromLineNum", 1))
|
|
|
result = _executor_ref.log(log_date_time, log_id, from_line_num)
|
|
|
return jsonify(result)
|
|
|
|