perf: reduce desktop quit risk polling
Refresh quit risk only when quitting Use in-process status for Electron local server Avoid repeated scheduled task status scans
This commit is contained in:
@@ -156,6 +156,10 @@ export const registerScheduledTaskRoutes = (app, dependencies) => {
|
||||
|
||||
app.get('/api/openchamber/scheduled-tasks/status', async (_req, res) => {
|
||||
try {
|
||||
if (typeof scheduledTasksRuntime.getStatus === 'function') {
|
||||
return res.json(scheduledTasksRuntime.getStatus());
|
||||
}
|
||||
|
||||
const settings = await readSettingsFromDiskMigrated();
|
||||
const projects = sanitizeProjects(settings?.projects || []);
|
||||
|
||||
|
||||
@@ -739,11 +739,31 @@ export const createScheduledTasksRuntime = (deps) => {
|
||||
queue.length = 0;
|
||||
};
|
||||
|
||||
const getStatus = () => {
|
||||
let enabledCount = 0;
|
||||
for (const taskMap of tasksByProject.values()) {
|
||||
for (const task of taskMap.values()) {
|
||||
if (task?.enabled) {
|
||||
enabledCount += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const runningCount = runningTaskKeys.size;
|
||||
return {
|
||||
hasEnabledScheduledTasks: enabledCount > 0,
|
||||
hasRunningScheduledTasks: runningCount > 0,
|
||||
enabledScheduledTasksCount: enabledCount,
|
||||
runningScheduledTasksCount: runningCount,
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
start,
|
||||
stop,
|
||||
syncAllProjects,
|
||||
syncProject,
|
||||
runNow,
|
||||
getStatus,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user