diff --git a/lib/types/Timer.d.ts b/lib/types/Timer.d.ts index a3ee55d..24ad2f8 100644 --- a/lib/types/Timer.d.ts +++ b/lib/types/Timer.d.ts @@ -1,18 +1,21 @@ import { RecurrenceRule, RecurrenceSpecDateRange, RecurrenceSpecObjLit } from 'node-schedule'; -import { EntityDict } from './Entity'; +import { EntityDict, OperationResult } from './Entity'; import { EntityDict as BaseEntityDict } from '../base-app-domain'; import { AsyncContext } from '../store/AsyncRowStore'; import { Watcher } from './Watcher'; -import { OperationResult } from '.'; -type FreeOperateFn> = (context: Cxt) => Promise>; +import { Namespace } from 'socket.io'; +type FreeRoutineFn> = (context: Cxt, env: { + socket: Namespace; +}) => Promise>; +type FreeTimerFn> = (context: Cxt) => Promise>; export type FreeRoutine> = { name: string; - routine: FreeOperateFn; + routine: FreeRoutineFn; }; export type FreeTimer> = { name: string; cron: RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date | string | number; - timer: FreeOperateFn; + timer: FreeTimerFn; singleton?: true; }; export type Routine> = FreeRoutine | Watcher; diff --git a/package.json b/package.json index af1de85..a673b53 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "dependencies": { "dayjs": "^1.11.9", "node-schedule": "^2.1.1", + "socket.io": "^4.7.2", "uuid": "^9.0.0", "webidl-conversions": "^5.0.0" } diff --git a/src/types/Timer.ts b/src/types/Timer.ts index 4287157..a292832 100644 --- a/src/types/Timer.ts +++ b/src/types/Timer.ts @@ -1,23 +1,28 @@ import { RecurrenceRule, RecurrenceSpecDateRange, RecurrenceSpecObjLit } from 'node-schedule'; -import { EntityDict } from './Entity'; +import { EntityDict, OperationResult } from './Entity'; import { EntityDict as BaseEntityDict } from '../base-app-domain'; import { AsyncContext } from '../store/AsyncRowStore'; import { Watcher } from './Watcher'; -import { OperationResult } from '.'; +import { Namespace } from 'socket.io'; -type FreeOperateFn> = ( - context: Cxt +type FreeRoutineFn> = ( + context: Cxt, + env: { + socket: Namespace; + } ) => Promise>; +type FreeTimerFn> = (context: Cxt) => Promise>; + export type FreeRoutine> = { name: string; - routine: FreeOperateFn; + routine: FreeRoutineFn; }; export type FreeTimer> = { name: string; cron: RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date | string | number; - timer: FreeOperateFn; + timer: FreeTimerFn; singleton?: true; // 置singleton意味着在集群环境中只有一个进程会去执行 };