@ruiapp/rapid-core 0.6.2 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -0
- package/dist/plugins/cronJob/CronJobPluginTypes.d.ts +14 -0
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/plugins/cronJob/CronJobPlugin.ts +1 -0
- package/src/plugins/cronJob/CronJobPluginTypes.ts +17 -1
- package/src/server.ts +3 -0
- package/src/types.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -4586,6 +4586,9 @@ class RapidServer {
|
|
|
4586
4586
|
}
|
|
4587
4587
|
async #handleEntityEvent(eventName, sender, payload, routerContext) {
|
|
4588
4588
|
const { modelSingularCode, baseModelSingularCode } = payload;
|
|
4589
|
+
if (!routerContext) {
|
|
4590
|
+
routerContext = new RouteContext(this);
|
|
4591
|
+
}
|
|
4589
4592
|
const entityWatchHandlerContext = {
|
|
4590
4593
|
server: this,
|
|
4591
4594
|
payload,
|
|
@@ -8457,6 +8460,7 @@ class CronJobPlugin {
|
|
|
8457
8460
|
async onApplicationReady(server, applicationConfig) {
|
|
8458
8461
|
for (const job of this.#jobs) {
|
|
8459
8462
|
const jobInstance = cron__namespace.CronJob.from({
|
|
8463
|
+
...(job.jobOptions || {}),
|
|
8460
8464
|
cronTime: job.cronTime,
|
|
8461
8465
|
onTick: async () => {
|
|
8462
8466
|
server.getLogger().info(`Executing cron job '${job.code}'...`);
|
|
@@ -12,6 +12,10 @@ export interface CronJobConfiguration {
|
|
|
12
12
|
* crontab 表达式
|
|
13
13
|
*/
|
|
14
14
|
cronTime: string;
|
|
15
|
+
/**
|
|
16
|
+
* 任务设置
|
|
17
|
+
*/
|
|
18
|
+
jobOptions?: CronJobOptions;
|
|
15
19
|
/**
|
|
16
20
|
* 任务处理程序编号。当指定处理程序编号时,忽略 handler 配置。
|
|
17
21
|
*/
|
|
@@ -28,6 +32,16 @@ export interface CronJobConfiguration {
|
|
|
28
32
|
*/
|
|
29
33
|
handleOptions?: any;
|
|
30
34
|
}
|
|
35
|
+
export interface CronJobOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Instantly triggers the onTick function post initialization. Default is false.
|
|
38
|
+
*/
|
|
39
|
+
runOnInit?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* If true, no additional instances of the onTick callback function will run until the current onTick callback has completed. Any new scheduled executions that occur while the current callback is running will be skipped entirely. Default is false.
|
|
42
|
+
*/
|
|
43
|
+
waitForCompletion?: boolean;
|
|
44
|
+
}
|
|
31
45
|
export interface CronJobPluginInitOptions {
|
|
32
46
|
jobs: CronJobConfiguration[];
|
|
33
47
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -618,7 +618,7 @@ export type EntityWatchHandler<TEventName extends keyof RpdServerEventTypes> = (
|
|
|
618
618
|
export type EntityWatchHandlerContext<TEventName extends keyof RpdServerEventTypes> = {
|
|
619
619
|
server: IRpdServer;
|
|
620
620
|
payload: RpdServerEventTypes[TEventName][1];
|
|
621
|
-
routerContext
|
|
621
|
+
routerContext: RouteContext;
|
|
622
622
|
};
|
|
623
623
|
export interface EntityWatchPluginInitOptions {
|
|
624
624
|
watchers: EntityWatcherType[];
|
package/package.json
CHANGED
|
@@ -71,6 +71,7 @@ class CronJobPlugin implements RapidPlugin {
|
|
|
71
71
|
async onApplicationReady(server: IRpdServer, applicationConfig: RpdApplicationConfig): Promise<any> {
|
|
72
72
|
for (const job of this.#jobs) {
|
|
73
73
|
const jobInstance = cron.CronJob.from({
|
|
74
|
+
...(job.jobOptions || {}),
|
|
74
75
|
cronTime: job.cronTime,
|
|
75
76
|
onTick: async () => {
|
|
76
77
|
server.getLogger().info(`Executing cron job '${job.code}'...`);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ActionHandlerContext } from "~/core/actionHandler";
|
|
2
|
-
import { RpdHttpMethod } from "~/types";
|
|
3
2
|
|
|
4
3
|
export interface CronJobConfiguration {
|
|
5
4
|
/**
|
|
@@ -17,6 +16,11 @@ export interface CronJobConfiguration {
|
|
|
17
16
|
*/
|
|
18
17
|
cronTime: string;
|
|
19
18
|
|
|
19
|
+
/**
|
|
20
|
+
* 任务设置
|
|
21
|
+
*/
|
|
22
|
+
jobOptions?: CronJobOptions;
|
|
23
|
+
|
|
20
24
|
/**
|
|
21
25
|
* 任务处理程序编号。当指定处理程序编号时,忽略 handler 配置。
|
|
22
26
|
*/
|
|
@@ -36,6 +40,18 @@ export interface CronJobConfiguration {
|
|
|
36
40
|
handleOptions?: any;
|
|
37
41
|
}
|
|
38
42
|
|
|
43
|
+
export interface CronJobOptions {
|
|
44
|
+
/**
|
|
45
|
+
* Instantly triggers the onTick function post initialization. Default is false.
|
|
46
|
+
*/
|
|
47
|
+
runOnInit?: boolean;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* If true, no additional instances of the onTick callback function will run until the current onTick callback has completed. Any new scheduled executions that occur while the current callback is running will be skipped entirely. Default is false.
|
|
51
|
+
*/
|
|
52
|
+
waitForCompletion?: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
39
55
|
export interface CronJobPluginInitOptions {
|
|
40
56
|
jobs: CronJobConfiguration[];
|
|
41
57
|
}
|
package/src/server.ts
CHANGED
|
@@ -445,6 +445,9 @@ export class RapidServer implements IRpdServer {
|
|
|
445
445
|
|
|
446
446
|
async #handleEntityEvent(eventName: keyof RpdServerEventTypes, sender: RapidPlugin, payload: RpdEntityCreateEventPayload, routerContext?: RouteContext) {
|
|
447
447
|
const { modelSingularCode, baseModelSingularCode } = payload;
|
|
448
|
+
if (!routerContext) {
|
|
449
|
+
routerContext = new RouteContext(this);
|
|
450
|
+
}
|
|
448
451
|
const entityWatchHandlerContext: EntityWatchHandlerContext<typeof eventName> = {
|
|
449
452
|
server: this,
|
|
450
453
|
payload,
|
package/src/types.ts
CHANGED
|
@@ -788,7 +788,7 @@ export type EntityWatchHandler<TEventName extends keyof RpdServerEventTypes> = (
|
|
|
788
788
|
export type EntityWatchHandlerContext<TEventName extends keyof RpdServerEventTypes> = {
|
|
789
789
|
server: IRpdServer;
|
|
790
790
|
payload: RpdServerEventTypes[TEventName][1];
|
|
791
|
-
routerContext
|
|
791
|
+
routerContext: RouteContext;
|
|
792
792
|
};
|
|
793
793
|
|
|
794
794
|
export interface EntityWatchPluginInitOptions {
|