feat: 修复停止逻辑
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
broadcastStopToContentScripts,
|
||||
cancelPendingCommands,
|
||||
clearStopRequest,
|
||||
createAutoRunSessionId,
|
||||
getAutoRunStatusPayload,
|
||||
getErrorMessage,
|
||||
getFirstUnfinishedStep,
|
||||
@@ -30,6 +31,7 @@
|
||||
runtime,
|
||||
setState,
|
||||
sleepWithStop,
|
||||
throwIfAutoRunSessionStopped,
|
||||
waitForRunningStepsToFinish,
|
||||
} = deps;
|
||||
|
||||
@@ -175,6 +177,7 @@
|
||||
currentRun: targetRun,
|
||||
totalRuns,
|
||||
attemptRun: currentRuntime.autoRunAttemptRun,
|
||||
autoRunSessionId: currentRuntime.autoRunSessionId,
|
||||
autoRunSkipFailures,
|
||||
roundSummaries,
|
||||
countdownTitle: '线程间隔中',
|
||||
@@ -206,6 +209,7 @@
|
||||
currentRun: targetRun,
|
||||
totalRuns,
|
||||
attemptRun: nextAttemptRun,
|
||||
autoRunSessionId: runtime.get().autoRunSessionId,
|
||||
autoRunSkipFailures,
|
||||
roundSummaries,
|
||||
countdownTitle: '线程间隔中',
|
||||
@@ -225,12 +229,14 @@
|
||||
await addLog(`自动运行异常终止:${getErrorMessage(error) || '未知错误'}`, 'error');
|
||||
}
|
||||
|
||||
runtime.set({ autoRunActive: false });
|
||||
runtime.set({ autoRunActive: false, autoRunSessionId: 0 });
|
||||
await broadcastAutoRunStatus('stopped', {
|
||||
currentRun: currentRuntime.autoRunCurrentRun,
|
||||
totalRuns: currentRuntime.autoRunTotalRuns,
|
||||
attemptRun: currentRuntime.autoRunAttemptRun,
|
||||
sessionId: 0,
|
||||
}, {
|
||||
autoRunSessionId: 0,
|
||||
autoRunTimerPlan: null,
|
||||
scheduledAutoRunPlan: null,
|
||||
});
|
||||
@@ -250,12 +256,22 @@
|
||||
return;
|
||||
}
|
||||
|
||||
let sessionId = Number.isInteger(options.autoRunSessionId) && options.autoRunSessionId > 0
|
||||
? options.autoRunSessionId
|
||||
: 0;
|
||||
if (sessionId) {
|
||||
throwIfAutoRunSessionStopped(sessionId);
|
||||
} else {
|
||||
sessionId = createAutoRunSessionId();
|
||||
}
|
||||
|
||||
clearStopRequest();
|
||||
runtime.set({
|
||||
autoRunActive: true,
|
||||
autoRunTotalRuns: totalRuns,
|
||||
autoRunCurrentRun: 0,
|
||||
autoRunAttemptRun: 0,
|
||||
autoRunSessionId: sessionId,
|
||||
});
|
||||
currentRuntime = runtime.get();
|
||||
|
||||
@@ -293,12 +309,14 @@
|
||||
const showResumePosition = continueCurrentOnFirstAttempt || resumeCurrentRun > 1 || resumeAttemptRun > 1;
|
||||
|
||||
await setState({
|
||||
autoRunSessionId: sessionId,
|
||||
autoRunSkipFailures,
|
||||
autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries),
|
||||
...getAutoRunStatusPayload(initialPhase, {
|
||||
currentRun: showResumePosition ? resumeCurrentRun : 0,
|
||||
totalRuns,
|
||||
attemptRun: showResumePosition ? resumeAttemptRun : 0,
|
||||
sessionId,
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -360,9 +378,10 @@
|
||||
cloudflareDomain: prevState.cloudflareDomain,
|
||||
cloudflareDomains: prevState.cloudflareDomains,
|
||||
autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries),
|
||||
autoRunSessionId: sessionId,
|
||||
tabRegistry: {},
|
||||
sourceLastUrls: {},
|
||||
...getAutoRunStatusPayload('running', { currentRun: targetRun, totalRuns, attemptRun }),
|
||||
...getAutoRunStatusPayload('running', { currentRun: targetRun, totalRuns, attemptRun, sessionId }),
|
||||
};
|
||||
await resetState();
|
||||
await setState(keepSettings);
|
||||
@@ -370,9 +389,10 @@
|
||||
await sleepWithStop(500);
|
||||
} else {
|
||||
await setState({
|
||||
autoRunSessionId: sessionId,
|
||||
autoRunSkipFailures,
|
||||
autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries),
|
||||
...getAutoRunStatusPayload('running', { currentRun: targetRun, totalRuns, attemptRun }),
|
||||
...getAutoRunStatusPayload('running', { currentRun: targetRun, totalRuns, attemptRun, sessionId }),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -397,11 +417,12 @@
|
||||
};
|
||||
|
||||
try {
|
||||
deps.throwIfStopped();
|
||||
throwIfAutoRunSessionStopped(sessionId);
|
||||
await broadcastAutoRunStatus('running', {
|
||||
currentRun: targetRun,
|
||||
totalRuns,
|
||||
attemptRun,
|
||||
sessionId,
|
||||
});
|
||||
|
||||
await runAutoSequenceFromStep(startStep, {
|
||||
@@ -428,6 +449,7 @@
|
||||
currentRun: targetRun,
|
||||
totalRuns,
|
||||
attemptRun,
|
||||
sessionId: 0,
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -453,6 +475,7 @@
|
||||
currentRun: targetRun,
|
||||
totalRuns,
|
||||
attemptRun,
|
||||
sessionId,
|
||||
});
|
||||
forceFreshTabsNextRun = true;
|
||||
await addLog(
|
||||
@@ -470,6 +493,7 @@
|
||||
currentRun: targetRun,
|
||||
totalRuns,
|
||||
attemptRun,
|
||||
sessionId: 0,
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -493,6 +517,7 @@
|
||||
currentRun: targetRun,
|
||||
totalRuns,
|
||||
attemptRun,
|
||||
sessionId: 0,
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -518,6 +543,7 @@
|
||||
currentRun: targetRun,
|
||||
totalRuns,
|
||||
attemptRun,
|
||||
sessionId: 0,
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -559,6 +585,7 @@
|
||||
currentRun: targetRun,
|
||||
totalRuns,
|
||||
attemptRun: runtime.get().autoRunAttemptRun,
|
||||
sessionId: 0,
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -584,6 +611,7 @@
|
||||
currentRun: finalRuntime.autoRunCurrentRun,
|
||||
totalRuns: finalRuntime.autoRunTotalRuns,
|
||||
attemptRun: finalRuntime.autoRunAttemptRun,
|
||||
sessionId: 0,
|
||||
});
|
||||
} else {
|
||||
await addLog(`=== 全部 ${finalRuntime.autoRunTotalRuns} 轮已执行完成,成功 ${successfulRuns} 轮 ===`, 'ok');
|
||||
@@ -591,11 +619,13 @@
|
||||
currentRun: finalRuntime.autoRunTotalRuns,
|
||||
totalRuns: finalRuntime.autoRunTotalRuns,
|
||||
attemptRun: finalRuntime.autoRunAttemptRun,
|
||||
sessionId: 0,
|
||||
});
|
||||
}
|
||||
runtime.set({ autoRunActive: false });
|
||||
runtime.set({ autoRunActive: false, autoRunSessionId: 0 });
|
||||
const afterRuntime = runtime.get();
|
||||
await setState({
|
||||
autoRunSessionId: 0,
|
||||
autoRunRoundSummaries: serializeAutoRunRoundSummaries(totalRuns, roundSummaries),
|
||||
autoRunTimerPlan: null,
|
||||
scheduledAutoRunPlan: null,
|
||||
@@ -603,6 +633,7 @@
|
||||
currentRun: deps.getStopRequested() || stoppedEarly ? afterRuntime.autoRunCurrentRun : afterRuntime.autoRunTotalRuns,
|
||||
totalRuns: afterRuntime.autoRunTotalRuns,
|
||||
attemptRun: afterRuntime.autoRunAttemptRun,
|
||||
sessionId: 0,
|
||||
}),
|
||||
});
|
||||
clearStopRequest();
|
||||
|
||||
Reference in New Issue
Block a user