fix(wechat): route scheduled task cancel and spec updates through Goose MCP
Pass cancel requests to Goose like create instead of inbound title matching, and add scheduled_task_update_spec so format or execution constraints update taskSpec without triggering page delivery guards. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -218,6 +218,51 @@ export function createScheduledTaskService(pool, { defaultTimezone = DEFAULT_TIM
|
||||
return rows.map(rowToTask);
|
||||
};
|
||||
|
||||
const updateTaskSpec = async ({
|
||||
userId,
|
||||
taskId,
|
||||
taskSpec = null,
|
||||
title = null,
|
||||
mergeTaskSpec = false,
|
||||
} = {}) => {
|
||||
if (!userId) throw new Error('缺少用户');
|
||||
const safeTaskId = String(taskId ?? '').trim();
|
||||
if (!safeTaskId) throw new Error('缺少 taskId');
|
||||
const safeTaskSpec = taskSpec == null ? null : String(taskSpec).trim();
|
||||
const safeTitle = title == null ? null : String(title).trim();
|
||||
if (!safeTaskSpec && !safeTitle) throw new Error('缺少 taskSpec 或 title');
|
||||
|
||||
const [rows] = await pool.query(
|
||||
`SELECT *
|
||||
FROM h5_scheduled_tasks
|
||||
WHERE id = ? AND user_id = ? AND status IN ('active', 'locked', 'failed')
|
||||
LIMIT 1`,
|
||||
[safeTaskId, userId],
|
||||
);
|
||||
const existing = rows[0];
|
||||
if (!existing) throw new Error('未找到可更新的定时任务');
|
||||
|
||||
let nextSpec = existing.task_spec;
|
||||
if (safeTaskSpec) {
|
||||
nextSpec = mergeTaskSpec
|
||||
? [String(existing.task_spec ?? '').trim(), safeTaskSpec].filter(Boolean).join('\n\n')
|
||||
: safeTaskSpec;
|
||||
}
|
||||
const nextTitle = safeTitle || existing.title;
|
||||
const ts = clock.now();
|
||||
await pool.query(
|
||||
`UPDATE h5_scheduled_tasks
|
||||
SET task_spec = ?, title = ?, updated_at = ?
|
||||
WHERE id = ?`,
|
||||
[nextSpec, nextTitle, ts, safeTaskId],
|
||||
);
|
||||
const [updated] = await pool.query(
|
||||
`SELECT * FROM h5_scheduled_tasks WHERE id = ? LIMIT 1`,
|
||||
[safeTaskId],
|
||||
);
|
||||
return rowToTask(updated[0]);
|
||||
};
|
||||
|
||||
const cancelTask = async ({
|
||||
userId,
|
||||
taskId = null,
|
||||
@@ -385,6 +430,7 @@ export function createScheduledTaskService(pool, { defaultTimezone = DEFAULT_TIM
|
||||
return {
|
||||
createTask,
|
||||
listTasks,
|
||||
updateTaskSpec,
|
||||
cancelTask,
|
||||
listDueTasks,
|
||||
lockTask,
|
||||
|
||||
Reference in New Issue
Block a user