上傳檔案到「modules/scheduled-tasks」

This commit is contained in:
X
2026-02-05 16:29:46 +00:00
parent 6171195350
commit c36efe6805

View File

@@ -541,9 +541,10 @@ async function __runTaskSingleInstance(taskName, jsRunner, signature = null) {
}; };
const clearIntervalSafe = (id) => { clearInterval(id); intervals.delete(id); }; const clearIntervalSafe = (id) => { clearInterval(id); intervals.delete(id); };
let jsRunnerResult;
entry.completion = (async () => { entry.completion = (async () => {
try { try {
await jsRunner({ addListener, setTimeoutSafe, clearTimeoutSafe, setIntervalSafe, clearIntervalSafe, abortSignal: abort.signal }); jsRunnerResult = await jsRunner({ addListener, setTimeoutSafe, clearTimeoutSafe, setIntervalSafe, clearIntervalSafe, abortSignal: abort.signal });
} finally { } finally {
try { abort.abort(); } catch {} try { abort.abort(); } catch {}
try { try {
@@ -553,6 +554,7 @@ async function __runTaskSingleInstance(taskName, jsRunner, signature = null) {
try { window?.dispatchEvent?.(new CustomEvent('xiaobaix-task-cleaned', { detail: { taskName, signature } })); } catch {} try { window?.dispatchEvent?.(new CustomEvent('xiaobaix-task-cleaned', { detail: { taskName, signature } })); } catch {}
__taskRunMap.delete(taskName); __taskRunMap.delete(taskName);
} }
return jsRunnerResult;
})(); })();
return entry.completion; return entry.completion;
@@ -585,7 +587,7 @@ async function processTaskCommands(commands, taskName) {
if (beforeJs) result = await executeSlashCommand(beforeJs); if (beforeJs) result = await executeSlashCommand(beforeJs);
const jsCode = match[1].trim(); const jsCode = match[1].trim();
if (jsCode) { if (jsCode) {
try { await executeTaskJS(jsCode, taskName || 'AnonymousTask'); } try { result = await executeTaskJS(jsCode, taskName || 'AnonymousTask'); }
catch (error) { catch (error) {
console.error(`[任务JS执行错误] ${error.message}`); console.error(`[任务JS执行错误] ${error.message}`);
try { xbLog.error('scheduledTasks', `taskjs error task=${String(taskName || 'AnonymousTask')}`, error); } catch {} try { xbLog.error('scheduledTasks', `taskjs error task=${String(taskName || 'AnonymousTask')}`, error); } catch {}
@@ -797,20 +799,21 @@ async function executeTaskJS(jsCode, taskName = 'AnonymousTask') {
checkStatus(); checkStatus();
}); });
let result;
try { try {
await runInScope(jsCode); result = await runInScope(jsCode);
await waitForAsyncSettled(); await waitForAsyncSettled();
} finally { } finally {
try { hardCleanup(); } finally { restoreGlobals(); } try { hardCleanup(); } finally { restoreGlobals(); }
} }
return result;
}; };
if (isLightTask) { if (isLightTask) {
__runTaskSingleInstance(stableKey, jsRunner, codeSig); return __runTaskSingleInstance(stableKey, jsRunner, codeSig);
return;
} }
await __runTaskSingleInstance(stableKey, jsRunner, codeSig); return await __runTaskSingleInstance(stableKey, jsRunner, codeSig);
} }
function handleTaskMessage(event) { function handleTaskMessage(event) {