fix(scheduled-task): release page delivery contracts before notifying users
Memind CI / Test, build, and release guards (push) Successful in 3m36s

Scheduled automation now prepares and retries MindSpace delivery contracts,
blocks WeChat pushes when public HTML links are not ready, and reconciles
stuck static preparing contracts on each worker scan.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-08-16 08:26:21 +08:00
parent 2b58cdc2c8
commit 7c0ed58ae1
4 changed files with 429 additions and 30 deletions
+55
View File
@@ -54,6 +54,7 @@ test('scheduled task worker executes due task and completes one-shot task', asyn
sessionId: 'session-1',
requestId: 'req-1',
deliveryText: '页面:https://example.com/news.html',
readyPaths: [],
}),
logger: { warn() {}, info() {} },
runOnStart: false,
@@ -224,6 +225,7 @@ test('scheduled task worker keeps success when wechat notification fails', async
sessionId: 'session-4',
requestId: 'req-4',
deliveryText: '页面已生成:https://example.com/news.html',
readyPaths: [],
}),
logger: { warn() {} },
runOnStart: false,
@@ -234,3 +236,56 @@ test('scheduled task worker keeps success when wechat notification fails', async
assert.deepEqual(calls, ['notify:web', 'success:task-4']);
});
test('scheduled task worker marks failure when page link is not deliverable yet', async () => {
const calls = [];
const task = {
id: 'task-5',
userId: 'user-5',
title: '每日新闻页',
recurrence: 'daily',
notifyChannel: 'web',
attempts: 1,
};
const worker = startScheduledTaskWorker({
intervalMs: 60_000,
userAuth: { id: 'user-auth' },
tkmindProxy: { id: 'proxy' },
scheduledTaskService: {
async listDueTasks() {
return [task];
},
async lockTask() {
return task;
},
async markTaskRunning(input) {
return input;
},
async markTaskSucceeded() {
calls.push('success');
},
async markTaskFailed(input, err) {
calls.push(`failed:${err.code}`);
return { ...input, status: 'failed', lastError: err.message };
},
},
scheduleService: {
async createUserNotification(input) {
calls.push(`notify:${input.notificationType}`);
},
},
executeTask: async () => ({
sessionId: 'session-5',
requestId: 'req-5',
deliveryText: '页面:https://m.tkmind.cn/MindSpace/user-5/public/daily-news.html',
readyPaths: [],
}),
logger: { warn() {} },
runOnStart: false,
});
await worker.runOnce();
worker.stop();
assert.deepEqual(calls, ['failed:SCHEDULED_TASK_NON_DELIVERY', 'notify:scheduled_task_failed']);
});