DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
feat(scheduler): 并发上限压住的任务显示等待中
hairyfa2f004cfadd0
diff --git a/packages/dsh-tauri-panel-scheduler/src/client/apis/index.type.ts b/packages/dsh-tauri-panel-scheduler/src/client/apis/index.type.tsindex ca9a7b23..2d7b9da9 100644--- a/packages/dsh-tauri-panel-scheduler/src/client/apis/index.type.ts+++ b/packages/dsh-tauri-panel-scheduler/src/client/apis/index.type.ts@@ -75,6 +75,7 @@ export type SchedulerTask = {updatedAt: string;lastRunAt?: string;nextRunAt?: string;+ waiting?: boolean;};export type SchedulerSchedule = OnceSchedule | HourlySchedule | DailySchedule | IntervalSchedule | WorkdaysSchedule | WeeklySchedule | MonthlySchedule | CustomSchedule;export type OnceSchedule = {diff --git a/packages/dsh-tauri-panel-scheduler/src/client/components/task-card.cssr.ts b/packages/dsh-tauri-panel-scheduler/src/client/components/task-card.cssr.tsindex 866334f5..849dcd0b 100644--- a/packages/dsh-tauri-panel-scheduler/src/client/components/task-card.cssr.ts+++ b/packages/dsh-tauri-panel-scheduler/src/client/components/task-card.cssr.ts@@ -15,4 +15,5 @@ export default c([c('.dshp-scheduler__card-meta', { display: 'flex', alignItems: 'center', gap: '10px', minWidth: '0' }),c('.dshp-scheduler__card-meta-text', { flex: '1', minWidth: '0', color: tertiary, fontSize: '12px', lineHeight: '18px', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }),c('.dshp-scheduler__card-meta-text strong', { color: secondary, fontWeight: '600' }),+ c('.dshp-scheduler__card-waiting', { flex: 'none', display: 'inline-flex', alignItems: 'center', height: '18px', padding: '0 6px', borderRadius: '6px', background: hover, color: 'var(--dsw-alias-state-business-primary)', fontSize: '11px', lineHeight: '18px', whiteSpace: 'nowrap' }),])diff --git a/packages/dsh-tauri-panel-scheduler/src/client/components/task-card.tsx b/packages/dsh-tauri-panel-scheduler/src/client/components/task-card.tsxindex 9e7dad75..b8d02c9b 100644--- a/packages/dsh-tauri-panel-scheduler/src/client/components/task-card.tsx+++ b/packages/dsh-tauri-panel-scheduler/src/client/components/task-card.tsx@@ -118,7 +118,9 @@ export function TaskCard({ task, t, describe, nextRun, paused, onEdit }: TaskCar): <strong>{t('paused')}</strong>}</span>-+ {task.waiting === true+ ? <span className="dshp-scheduler__card-waiting">{t('waiting')}</span>+ : null}</div></div><Menudiff --git a/packages/dsh-tauri-panel-scheduler/src/client/locales/index.ts b/packages/dsh-tauri-panel-scheduler/src/client/locales/index.tsindex 7b043e47..7d23b7d4 100644--- a/packages/dsh-tauri-panel-scheduler/src/client/locales/index.ts+++ b/packages/dsh-tauri-panel-scheduler/src/client/locales/index.ts@@ -95,6 +95,7 @@ const zh = {'cancelled': '已取消','queued': '排队中','running': '执行中',+ 'waiting': '等待中','triggerSchedule': '计划','triggerManual': '手动','startedAt': '开始时间',@@ -215,6 +216,7 @@ const en: Record<LocaleKey, string> = {'cancelled': 'Cancelled','queued': 'Queued','running': 'Running',+ 'waiting': 'Waiting','triggerSchedule': 'Schedule','triggerManual': 'Manual','startedAt': 'Started',diff --git a/packages/dsh-tauri-panel-scheduler/src/client/types/index.ts b/packages/dsh-tauri-panel-scheduler/src/client/types/index.tsindex 8f720c83..6ec2548b 100644--- a/packages/dsh-tauri-panel-scheduler/src/client/types/index.ts+++ b/packages/dsh-tauri-panel-scheduler/src/client/types/index.ts@@ -61,6 +61,7 @@ export interface TaskView {updatedAt: stringlastRunAt?: stringnextRunAt?: string+ waiting?: boolean}export type RunStatus = 'queued' | 'running' | 'succeeded' | 'failed' | 'interrupted' | 'skipped' | 'cancelled'diff --git a/packages/dsh-tauri-panel-scheduler/src/host/routes/tasks/get.ts b/packages/dsh-tauri-panel-scheduler/src/host/routes/tasks/get.tsindex 9b902285..0ec5d964 100644--- a/packages/dsh-tauri-panel-scheduler/src/host/routes/tasks/get.ts+++ b/packages/dsh-tauri-panel-scheduler/src/host/routes/tasks/get.ts@@ -2,10 +2,12 @@ import type { EventHandlerRequest } from 'dsh-tauri'import type { GetTasksQuery, TaskListResponse } from '../index.types'import { defineEventHandler, getQuery } from 'dsh-tauri'import { castArray } from 'lodash-es'+import { scheduler } from '../../service/scheduler'import { task } from '../../service/task'export default defineEventHandler<EventHandlerRequest, Promise<TaskListResponse>>(async (event) => {const raw = getQuery<GetTasksQuery>(event).searchconst search = castArray(raw)[0] ?? ''- return { tasks: await task.list(search) }+ const [tasks, waiting] = await Promise.all([task.list(search), scheduler.waitingIds()])+ return { tasks: tasks.map(item => waiting.has(item.id) ? { ...item, waiting: true } : item) }})diff --git a/packages/dsh-tauri-panel-scheduler/src/host/service/scheduler.ts b/packages/dsh-tauri-panel-scheduler/src/host/service/scheduler.tsindex 79de68eb..7fc12513 100644--- a/packages/dsh-tauri-panel-scheduler/src/host/service/scheduler.ts+++ b/packages/dsh-tauri-panel-scheduler/src/host/service/scheduler.ts@@ -3,6 +3,7 @@ import { defineService } from 'dsh-tauri'import { filter, isEmpty, isNil, take } from 'lodash-es'import { getCurrentHostInstance } from '../config/runtime'import { nextOccurrence } from '../utils/schedule'+import { isTaskDue, selectWaitingTaskIds } from '../utils/waiting'import { executor } from './executor'import { task } from './task'@@ -38,11 +39,15 @@ export const scheduler = defineService({if (occurrence !== undefined)await task.advance(item.id, item.lastRunAt, new Date(occurrence).toISOString())}- const pending = filter(all, item =>- item.enabled && !isNil(item.nextRunAt) && !running.has(item.id) && new Date(item.nextRunAt).getTime() <= now)+ const pending = filter(all, item => isTaskDue(item, now) && !running.has(item.id))for (const item of take(pending, SCHEDULER_MAX_CONCURRENT_RUNS - running.size))void fire(item, 'schedule')},++ async waitingIds(): Promise<Set<string>> {+ const all = await task.list()+ return selectWaitingTaskIds(all, running, SCHEDULER_MAX_CONCURRENT_RUNS - running.size, Date.now())+ },})// --- internal ---diff --git a/packages/dsh-tauri-panel-scheduler/src/host/types/index.ts b/packages/dsh-tauri-panel-scheduler/src/host/types/index.tsindex 2a0f7ef4..f247a08c 100644--- a/packages/dsh-tauri-panel-scheduler/src/host/types/index.ts+++ b/packages/dsh-tauri-panel-scheduler/src/host/types/index.ts@@ -93,6 +93,8 @@ export interface SchedulerTask {updatedAt: stringlastRunAt?: stringnextRunAt?: string+ /** 派生视图字段:已到点但受并发上限压住未启动;不落盘,读取路径每次重算。 */+ waiting?: boolean}export interface SchedulerRun {diff --git a/packages/dsh-tauri-panel-scheduler/src/host/utils/waiting.test.ts b/packages/dsh-tauri-panel-scheduler/src/host/utils/waiting.test.tsnew file mode 100644index 00000000..e8d094d5--- /dev/null+++ b/packages/dsh-tauri-panel-scheduler/src/host/utils/waiting.test.ts@@ -0,0 +1,51 @@+import type { SchedulerTask } from '../types'+import { describe, expect, it } from 'vitest'+import { isTaskDue, selectWaitingTaskIds } from './waiting'++const NOW = Date.parse('2026-09-16T10:00:00.000Z')+const DUE = '2026-09-16T09:59:00.000Z'+const FUTURE = '2026-09-16T11:00:00.000Z'++function makeTask(id: string, nextRunAt?: string, enabled = true): SchedulerTask {+ return {+ id,+ name: id,+ prompt: 'prompt',+ schedule: { kind: 'daily', time: '09:00', timeZone: 'UTC' },+ enabled,+ createdAt: '2026-09-16T00:00:00.000Z',+ updatedAt: '2026-09-16T00:00:00.000Z',+ nextRunAt,+ }+}++describe('isTaskDue', () => {+ it('treats an enabled task whose nextRunAt has passed as due', () => {+ expect(isTaskDue(makeTask('a', DUE), NOW)).toBe(true)+ expect(isTaskDue(makeTask('a', DUE, false), NOW)).toBe(false)+ expect(isTaskDue(makeTask('a', FUTURE), NOW)).toBe(false)+ expect(isTaskDue(makeTask('a'), NOW)).toBe(false)+ })+})++describe('selectWaitingTaskIds', () => {+ it('marks every due task as waiting when no capacity is left', () => {+ const tasks = [makeTask('a', DUE), makeTask('b', DUE)]+ expect([...selectWaitingTaskIds(tasks, new Set(), 0, NOW)]).toEqual(['a', 'b'])+ })++ it('keeps the tasks that this tick can start out of the waiting set', () => {+ const tasks = [makeTask('a', DUE), makeTask('b', DUE), makeTask('c', DUE)]+ expect([...selectWaitingTaskIds(tasks, new Set(), 1, NOW)]).toEqual(['b', 'c'])+ })++ it('counts in-flight runs against the capacity', () => {+ const tasks = [makeTask('a', DUE), makeTask('b', DUE)]+ expect([...selectWaitingTaskIds(tasks, new Set(['z']), 1, NOW)]).toEqual(['b'])+ })++ it('never marks a running, paused or future task as waiting', () => {+ const tasks = [makeTask('a', DUE), makeTask('b', DUE, false), makeTask('c', FUTURE)]+ expect([...selectWaitingTaskIds(tasks, new Set(['a']), 0, NOW)]).toEqual([])+ })+})diff --git a/packages/dsh-tauri-panel-scheduler/src/host/utils/waiting.ts b/packages/dsh-tauri-panel-scheduler/src/host/utils/waiting.tsnew file mode 100644index 00000000..3544eda7--- /dev/null+++ b/packages/dsh-tauri-panel-scheduler/src/host/utils/waiting.ts@@ -0,0 +1,16 @@+import type { SchedulerTask } from '../types'+import { isNil } from 'lodash-es'++export function isTaskDue(item: Pick<SchedulerTask, 'enabled' | 'nextRunAt'>, now: number): boolean {+ return item.enabled && !isNil(item.nextRunAt) && new Date(item.nextRunAt).getTime() <= now+}++export function selectWaitingTaskIds(+ items: readonly SchedulerTask[],+ runningIds: ReadonlySet<string>,+ capacity: number,+ now: number,+): Set<string> {+ const pending = items.filter(item => isTaskDue(item, now) && !runningIds.has(item.id))+ return new Set(pending.slice(Math.max(0, capacity)).map(item => item.id))+}