From 9ad4b0ef6f25ed3367ddf41499aef2d0591f08d3 Mon Sep 17 00:00:00 2001 From: Xc Date: Wed, 13 Nov 2024 16:25:28 +0800 Subject: [PATCH] =?UTF-8?q?freeRoutine=E5=A2=9E=E5=8A=A0=E4=BA=86socket?= =?UTF-8?q?=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/types/Timer.d.ts | 13 ++++++++----- package.json | 1 + src/types/Timer.ts | 17 +++++++++++------ 3 files changed, 20 insertions(+), 11 deletions(-) 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意味着在集群环境中只有一个进程会去执行 };