perf: 任务支持禁用

This commit is contained in:
xiaojunnuo
2024-09-11 16:49:50 +08:00
parent 5b0f5f75d0
commit 8ed16b3ea2
8 changed files with 61 additions and 12 deletions
+9 -2
View File
@@ -104,11 +104,18 @@ export class Executor {
async runWithHistory(runnable: Runnable, runnableType: string, run: () => Promise<ResultType | void>) {
runnable.runnableType = runnableType;
this.runtime.start(runnable);
// const timeout = runnable.timeout ?? 20 * 60 * 1000;
await this.onChanged(this.runtime);
try {
if (runnable.disabled) {
//该任务被禁用
this.runtime.disabled(runnable);
return ResultType.disabled;
}
await this.onChanged(this.runtime);
if (this.abort.signal.aborted) {
this.runtime.cancel(runnable);
return ResultType.canceled;
@@ -74,6 +74,17 @@ export class RunHistory {
this.log(runnable, `跳过`);
}
disabled(runnable: Runnable) {
const now = new Date().getTime();
const status = runnable.status;
_.merge(status, {
status: "canceled",
endTime: now,
result: "disabled",
});
this.log(runnable, `禁用`);
}
error(runnable: Runnable, e: Error) {
const now = new Date().getTime();
const status = runnable.status;
@@ -70,6 +70,7 @@ export type Runnable = {
default?: {
[key: string]: any;
};
disabled?: boolean;
};
export type EmailOptions = {
@@ -108,6 +109,7 @@ export enum ResultType {
error = "error",
canceled = "canceled",
skip = "skip",
disabled = "disabled",
none = "none",
}