fix: recover interrupted schedules

This commit is contained in:
lofyer
2026-08-13 01:41:52 +08:00
parent 8cd23bada1
commit 67cb69f07d
3 changed files with 264 additions and 49 deletions
+22 -4
View File
@@ -1033,6 +1033,9 @@ export function registerIpcHandlers(
origin: origin === 'channel' ? 'delegation' : origin
})
}
if (origin === 'schedule') {
assistantDatabase.bindScheduleRunTask(schedule.id, requestId)
}
const modeInstruction =
schedule.workMode === 'execute'
? 'Work mode: Execute. Follow the request using the selected backend. Tool actions must remain within the configured workspace, sandbox, enabled capabilities, and security policy.'
@@ -1400,8 +1403,15 @@ export function registerIpcHandlers(
}
scheduleTickRunning = true
try {
for (const schedule of assistantDatabase.claimDueSchedules()) {
await trackExecution(executeSchedule(schedule))
for (const claim of assistantDatabase.claimDueSchedules()) {
const result = await trackExecution(
executeSchedule(claim.schedule)
)
assistantDatabase.completeScheduleRun(
claim.runId,
result.status,
assistantDatabase.getScheduleRunTaskId(claim.runId)
)
}
if (!shuttingDown && !executionPaused) {
await trackExecution(heartbeatService.processDue())
@@ -3531,10 +3541,18 @@ export function registerIpcHandlers(
if (executionPaused || shuttingDown) {
throw new Error('本地数据维护期间暂不接受新任务')
}
const schedule = assistantDatabase.claimScheduleNow(
const claim = assistantDatabase.claimScheduleNow(
assistantIdSchema.parse(input)
)
void trackExecution(executeSchedule(schedule)).catch(() => undefined)
void trackExecution(executeSchedule(claim.schedule))
.then((result) => {
assistantDatabase.completeScheduleRun(
claim.runId,
result.status,
assistantDatabase.getScheduleRunTaskId(claim.runId)
)
})
.catch(() => undefined)
})
ipcMain.handle(ipcChannels.heartbeatsList, (event, input: unknown) => {