run_task_async
Start scheduled tasks in Qinglong Panel without waiting for completion, enabling background execution for improved workflow efficiency.
Instructions
异步启动任务,不等待执行完成
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| task_id | Yes | 任务 ID |
Implementation Reference
- server.py:216-246 (handler)The main handler function for the 'run_task_async' tool. It extracts the task_id from arguments, authenticates with a Bearer token, sends a PUT request to the Qinglong API endpoint /open/crons/run with the task_id in the body, and responds with a success message if the API returns code 200, or an error otherwise.elif tool_name == "run_task_async": task_id = arguments.get("task_id") try: url = f"{QINGLONG_URL}/open/crons/run" headers = {"Authorization": f"Bearer {token}"} data = [task_id] resp = requests.put(url, headers=headers, json=data, timeout=10) result = resp.json() except Exception as e: response = { "jsonrpc": "2.0", "id": request["id"], "error": {"code": -32603, "message": f"请求失败: {str(e)}"} } print(json.dumps(response), flush=True) continue if result.get("code") == 200: response = { "jsonrpc": "2.0", "id": request["id"], "result": {"content": [{"type": "text", "text": f"任务 {task_id} 已成功启动"}]} } else: response = { "jsonrpc": "2.0", "id": request["id"], "error": {"code": -32603, "message": f"运行任务失败: {result}"} }
- server.py:101-110 (schema)The tool schema definition for 'run_task_async', including name, description, and input schema requiring a single 'task_id' integer parameter.{ "name": "run_task_async", "description": "异步启动任务,不等待执行完成", "inputSchema": { "type": "object", "properties": { "task_id": {"type": "integer", "description": "任务 ID"} }, "required": ["task_id"] }
- server.py:81-155 (registration)The tool is registered in the 'tools/list' RPC method response, where the list of available tools includes 'run_task_async' with its schema."tools": [ { "name": "list_qinglong_tasks", "description": "查询青龙面板中的所有定时任务列表", "inputSchema": { "type": "object", "properties": {} } }, { "name": "run_task", "description": "执行任务并等待完成,返回执行日志(最多等待30秒)", "inputSchema": { "type": "object", "properties": { "task_id": {"type": "integer", "description": "任务 ID"} }, "required": ["task_id"] } }, { "name": "run_task_async", "description": "异步启动任务,不等待执行完成", "inputSchema": { "type": "object", "properties": { "task_id": {"type": "integer", "description": "任务 ID"} }, "required": ["task_id"] } }, { "name": "get_task_logs", "description": "获取青龙面板中指定任务的执行日志", "inputSchema": { "type": "object", "properties": { "task_id": {"type": "integer", "description": "任务 ID"} }, "required": ["task_id"] } }, { "name": "get_task_status", "description": "获取青龙面板中指定任务的执行状态", "inputSchema": { "type": "object", "properties": { "task_id": {"type": "integer", "description": "任务 ID"} }, "required": ["task_id"] } }, { "name": "list_subscriptions", "description": "查询青龙面板中的所有订阅列表", "inputSchema": { "type": "object", "properties": {} } }, { "name": "run_subscription", "description": "运行指定的订阅", "inputSchema": { "type": "object", "properties": { "subscription_id": {"type": "integer", "description": "订阅 ID"} }, "required": ["subscription_id"] } } ] } }