mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 11:20:21 +00:00
UI: dedupe cron busy-state request flow
This commit is contained in:
@@ -223,6 +223,25 @@ export async function loadCronModelSuggestions(state: CronModelSuggestionsState)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function withCronBusy(
|
||||||
|
state: CronState,
|
||||||
|
run: (client: GatewayBrowserClient) => Promise<void>,
|
||||||
|
) {
|
||||||
|
const client = state.client;
|
||||||
|
if (!client || !state.connected || state.cronBusy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state.cronBusy = true;
|
||||||
|
state.cronError = null;
|
||||||
|
try {
|
||||||
|
await run(client);
|
||||||
|
} catch (err) {
|
||||||
|
state.cronError = String(err);
|
||||||
|
} finally {
|
||||||
|
state.cronBusy = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function loadCronJobs(state: CronState) {
|
export async function loadCronJobs(state: CronState) {
|
||||||
return await loadCronJobsPage(state, { append: false });
|
return await loadCronJobsPage(state, { append: false });
|
||||||
}
|
}
|
||||||
@@ -627,12 +646,7 @@ function buildFailureAlert(form: CronFormState) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function addCronJob(state: CronState) {
|
export async function addCronJob(state: CronState) {
|
||||||
if (!state.client || !state.connected || state.cronBusy) {
|
await withCronBusy(state, async (client) => {
|
||||||
return;
|
|
||||||
}
|
|
||||||
state.cronBusy = true;
|
|
||||||
state.cronError = null;
|
|
||||||
try {
|
|
||||||
const form = normalizeCronFormState(state.cronForm);
|
const form = normalizeCronFormState(state.cronForm);
|
||||||
if (form !== state.cronForm) {
|
if (form !== state.cronForm) {
|
||||||
state.cronForm = form;
|
state.cronForm = form;
|
||||||
@@ -698,69 +712,42 @@ export async function addCronJob(state: CronState) {
|
|||||||
throw new Error(t("cron.errors.nameRequiredShort"));
|
throw new Error(t("cron.errors.nameRequiredShort"));
|
||||||
}
|
}
|
||||||
if (state.cronEditingJobId) {
|
if (state.cronEditingJobId) {
|
||||||
await state.client.request("cron.update", {
|
await client.request("cron.update", {
|
||||||
id: state.cronEditingJobId,
|
id: state.cronEditingJobId,
|
||||||
patch: job,
|
patch: job,
|
||||||
});
|
});
|
||||||
clearCronEditState(state);
|
clearCronEditState(state);
|
||||||
} else {
|
} else {
|
||||||
await state.client.request("cron.add", job);
|
await client.request("cron.add", job);
|
||||||
resetCronFormToDefaults(state);
|
resetCronFormToDefaults(state);
|
||||||
}
|
}
|
||||||
await loadCronJobs(state);
|
await loadCronJobs(state);
|
||||||
await loadCronStatus(state);
|
await loadCronStatus(state);
|
||||||
} catch (err) {
|
});
|
||||||
state.cronError = String(err);
|
|
||||||
} finally {
|
|
||||||
state.cronBusy = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function toggleCronJob(state: CronState, job: CronJob, enabled: boolean) {
|
export async function toggleCronJob(state: CronState, job: CronJob, enabled: boolean) {
|
||||||
if (!state.client || !state.connected || state.cronBusy) {
|
await withCronBusy(state, async (client) => {
|
||||||
return;
|
await client.request("cron.update", { id: job.id, patch: { enabled } });
|
||||||
}
|
|
||||||
state.cronBusy = true;
|
|
||||||
state.cronError = null;
|
|
||||||
try {
|
|
||||||
await state.client.request("cron.update", { id: job.id, patch: { enabled } });
|
|
||||||
await loadCronJobs(state);
|
await loadCronJobs(state);
|
||||||
await loadCronStatus(state);
|
await loadCronStatus(state);
|
||||||
} catch (err) {
|
});
|
||||||
state.cronError = String(err);
|
|
||||||
} finally {
|
|
||||||
state.cronBusy = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function runCronJob(state: CronState, job: CronJob, mode: "force" | "due" = "force") {
|
export async function runCronJob(state: CronState, job: CronJob, mode: "force" | "due" = "force") {
|
||||||
if (!state.client || !state.connected || state.cronBusy) {
|
await withCronBusy(state, async (client) => {
|
||||||
return;
|
await client.request("cron.run", { id: job.id, mode });
|
||||||
}
|
|
||||||
state.cronBusy = true;
|
|
||||||
state.cronError = null;
|
|
||||||
try {
|
|
||||||
await state.client.request("cron.run", { id: job.id, mode });
|
|
||||||
if (state.cronRunsScope === "all") {
|
if (state.cronRunsScope === "all") {
|
||||||
await loadCronRuns(state, null);
|
await loadCronRuns(state, null);
|
||||||
} else {
|
} else {
|
||||||
await loadCronRuns(state, job.id);
|
await loadCronRuns(state, job.id);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
});
|
||||||
state.cronError = String(err);
|
|
||||||
} finally {
|
|
||||||
state.cronBusy = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function removeCronJob(state: CronState, job: CronJob) {
|
export async function removeCronJob(state: CronState, job: CronJob) {
|
||||||
if (!state.client || !state.connected || state.cronBusy) {
|
await withCronBusy(state, async (client) => {
|
||||||
return;
|
await client.request("cron.remove", { id: job.id });
|
||||||
}
|
|
||||||
state.cronBusy = true;
|
|
||||||
state.cronError = null;
|
|
||||||
try {
|
|
||||||
await state.client.request("cron.remove", { id: job.id });
|
|
||||||
if (state.cronEditingJobId === job.id) {
|
if (state.cronEditingJobId === job.id) {
|
||||||
clearCronEditState(state);
|
clearCronEditState(state);
|
||||||
}
|
}
|
||||||
@@ -773,11 +760,7 @@ export async function removeCronJob(state: CronState, job: CronJob) {
|
|||||||
}
|
}
|
||||||
await loadCronJobs(state);
|
await loadCronJobs(state);
|
||||||
await loadCronStatus(state);
|
await loadCronStatus(state);
|
||||||
} catch (err) {
|
});
|
||||||
state.cronError = String(err);
|
|
||||||
} finally {
|
|
||||||
state.cronBusy = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadCronRuns(
|
export async function loadCronRuns(
|
||||||
|
|||||||
Reference in New Issue
Block a user