vona-module-a-startup 5.0.10 → 5.0.12
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 +190 -3
- package/dist/service/startup.d.ts +5 -4
- package/package.json +2 -2
- package/dist/.metadata/index.js +0 -36
- package/dist/.metadata/this.js +0 -2
- package/dist/bean/cacheRedis.startupDebounce.js +0 -13
- package/dist/bean/meta.redlock.js +0 -14
- package/dist/config/config.js +0 -7
- package/dist/lib/index.js +0 -1
- package/dist/lib/startup.js +0 -4
- package/dist/monkey.js +0 -10
- package/dist/service/startup.js +0 -142
- package/dist/types/index.js +0 -1
- package/dist/types/startup.js +0 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,190 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { BeanInfo, BeanSimple, BeanBase, cast, BeanScopeBase, createBeanDecorator } from 'vona';
|
|
2
|
+
import { Scope } from 'vona-module-a-bean';
|
|
3
|
+
import { CacheRedis, BeanCacheRedisBase } from 'vona-module-a-cache';
|
|
4
|
+
import { Meta } from 'vona-module-a-meta';
|
|
5
|
+
import { BeanRedlockBase } from 'vona-module-a-redlock';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { isNil } from '@cabloy/utils';
|
|
8
|
+
import fse from 'fs-extra';
|
|
9
|
+
import { Service } from 'vona-module-a-web';
|
|
10
|
+
|
|
11
|
+
var _dec$3, _dec2$3, _class$3;
|
|
12
|
+
let CacheRedisStartupDebounce = (_dec$3 = CacheRedis(), _dec2$3 = BeanInfo({
|
|
13
|
+
module: "a-startup"
|
|
14
|
+
}), _dec$3(_class$3 = _dec2$3(_class$3 = class CacheRedisStartupDebounce extends BeanCacheRedisBase {}) || _class$3) || _class$3);
|
|
15
|
+
|
|
16
|
+
var _dec$2, _dec2$2, _class$2;
|
|
17
|
+
let MetaRedlock = (_dec$2 = Meta(), _dec2$2 = BeanInfo({
|
|
18
|
+
module: "a-startup"
|
|
19
|
+
}), _dec$2(_class$2 = _dec2$2(_class$2 = class MetaRedlock extends BeanRedlockBase {}) || _class$2) || _class$2);
|
|
20
|
+
|
|
21
|
+
function config(_app) {
|
|
22
|
+
return {
|
|
23
|
+
startup: {
|
|
24
|
+
debounce: 10 * 1000
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const __ThisModule__ = 'a-startup';
|
|
30
|
+
|
|
31
|
+
class Monkey extends BeanSimple {
|
|
32
|
+
async appStart() {
|
|
33
|
+
await this.bean.scope(__ThisModule__).service.startup.appStart();
|
|
34
|
+
}
|
|
35
|
+
async appReady() {
|
|
36
|
+
await this.bean.scope(__ThisModule__).service.startup.appReady();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
var _dec$1, _dec2$1, _class$1;
|
|
41
|
+
let ServiceStartup = (_dec$1 = Service(), _dec2$1 = BeanInfo({
|
|
42
|
+
module: "a-startup"
|
|
43
|
+
}), _dec$1(_class$1 = _dec2$1(_class$1 = class ServiceStartup extends BeanBase {
|
|
44
|
+
async appStart() {
|
|
45
|
+
// clear keys
|
|
46
|
+
await this._clearResources();
|
|
47
|
+
|
|
48
|
+
// run startups: not after
|
|
49
|
+
for (const startup of this._startups) {
|
|
50
|
+
const startupOptions = startup.beanOptions.options;
|
|
51
|
+
if (!startupOptions?.instance && startupOptions?.after !== true) {
|
|
52
|
+
await this.runStartup(startup.name, null);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async appReady() {
|
|
57
|
+
// run startups: after
|
|
58
|
+
for (const startup of this._startups) {
|
|
59
|
+
const startupOptions = startup.beanOptions.options;
|
|
60
|
+
if (!startupOptions?.instance && startupOptions?.after === true) {
|
|
61
|
+
await this.runStartup(startup.name, null);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// version init : force: should be false
|
|
66
|
+
if (this.app.meta.isTest || this.app.meta.isLocal) {
|
|
67
|
+
const instanceName = '';
|
|
68
|
+
await this.bean.executor.newCtx(async () => {
|
|
69
|
+
await this.$scope.instance.service.instance.instanceStartup(instanceName, {
|
|
70
|
+
force: false
|
|
71
|
+
});
|
|
72
|
+
}, {
|
|
73
|
+
dbInfo: true,
|
|
74
|
+
instanceName
|
|
75
|
+
});
|
|
76
|
+
} else {
|
|
77
|
+
// all instances
|
|
78
|
+
const instances = await this.bean.executor.newCtx(async () => {
|
|
79
|
+
return await this.bean.instance.list();
|
|
80
|
+
}, {
|
|
81
|
+
dbInfo: true
|
|
82
|
+
});
|
|
83
|
+
for (const instance of instances) {
|
|
84
|
+
const instanceName = instance.name;
|
|
85
|
+
// need not await
|
|
86
|
+
this.bean.executor.newCtx(async () => {
|
|
87
|
+
await this.$scope.instance.service.instance.instanceStartup(instanceName, {
|
|
88
|
+
force: false
|
|
89
|
+
});
|
|
90
|
+
}, {
|
|
91
|
+
dbInfo: true,
|
|
92
|
+
instanceName
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// version test
|
|
98
|
+
if (this.app.meta.isTest) {
|
|
99
|
+
const instanceName = '';
|
|
100
|
+
await this.bean.executor.newCtx(async () => {
|
|
101
|
+
await this.$scope.version.service.version.__instanceTest(instanceName);
|
|
102
|
+
}, {
|
|
103
|
+
dbInfo: true,
|
|
104
|
+
instanceName
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
async runStartup(startupName, instanceName, options) {
|
|
109
|
+
const startup = this.bean.onion.startup.onionsNormal[startupName];
|
|
110
|
+
const startupOptions = startup.beanOptions.options;
|
|
111
|
+
// normal
|
|
112
|
+
if (!startupOptions.debounce) {
|
|
113
|
+
return await this._runStartupInner(startup, instanceName, options);
|
|
114
|
+
}
|
|
115
|
+
// debounce: lock
|
|
116
|
+
return await this.scope.redlock.lockIsolate(`startup.${startupName}`, async () => {
|
|
117
|
+
return await this._runStartupLock(startup, instanceName, options);
|
|
118
|
+
}, {
|
|
119
|
+
instanceName
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
async _runStartupLock(startup, instanceName, options) {
|
|
123
|
+
// ignore debounce for test
|
|
124
|
+
if (!options?.force && !this.app.meta.isTest) {
|
|
125
|
+
const startupOptions = startup.beanOptions.options;
|
|
126
|
+
const cacheKey = `startupDebounce:${startup.name}${!isNil(instanceName) ? `:${this.ctx.instance.id}` : ''}`;
|
|
127
|
+
const debounce = typeof startupOptions.debounce === 'number' ? startupOptions.debounce : this.scope.config.startup.debounce;
|
|
128
|
+
const flag = await this.scope.cacheRedis.startupDebounce.getset(true, cacheKey, {
|
|
129
|
+
ttl: debounce
|
|
130
|
+
});
|
|
131
|
+
if (flag) return;
|
|
132
|
+
}
|
|
133
|
+
// perform
|
|
134
|
+
await this._runStartupInner(startup, instanceName, options);
|
|
135
|
+
}
|
|
136
|
+
async _runStartupInner(startup, instanceName, options) {
|
|
137
|
+
this.$logger.silly(`startup${startup.beanOptions?.options?.instance ? ' instance' : ''}: ${startup.name}, pid: ${process.pid}`);
|
|
138
|
+
const startupOptions = startup.beanOptions.options;
|
|
139
|
+
// execute
|
|
140
|
+
return await this.bean.executor.newCtx(async () => {
|
|
141
|
+
const bean = cast(this.bean._getBean(startup.beanOptions.beanFullName));
|
|
142
|
+
await bean.execute(options);
|
|
143
|
+
}, {
|
|
144
|
+
dbInfo: true,
|
|
145
|
+
instanceName,
|
|
146
|
+
transaction: startupOptions.transaction
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
async runStartupInstance(instanceName, options) {
|
|
150
|
+
// run startups: not after
|
|
151
|
+
for (const startup of this._startups) {
|
|
152
|
+
const startupOptions = startup.beanOptions.options;
|
|
153
|
+
if (startupOptions?.instance && startupOptions?.after !== true) {
|
|
154
|
+
await this.runStartup(startup.name, instanceName, options);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// set flag
|
|
158
|
+
this.app.meta.appReadyInstances[instanceName] = true;
|
|
159
|
+
// run startups: after
|
|
160
|
+
for (const startup of this._startups) {
|
|
161
|
+
const startupOptions = startup.beanOptions.options;
|
|
162
|
+
if (startupOptions?.instance && startupOptions?.after === true) {
|
|
163
|
+
await this.runStartup(startup.name, instanceName, options);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
get _startups() {
|
|
168
|
+
return this.bean.onion.startup.getOnionsEnabled();
|
|
169
|
+
}
|
|
170
|
+
async _clearResources() {
|
|
171
|
+
if (!this.app.meta.isTest) return;
|
|
172
|
+
// redis
|
|
173
|
+
await this.$scope.redis.service.redisClient.clearAllData();
|
|
174
|
+
// .app/public
|
|
175
|
+
await fse.remove(path.join(this.app.config.server.publicDir, '1'));
|
|
176
|
+
}
|
|
177
|
+
}) || _class$1) || _class$1);
|
|
178
|
+
|
|
179
|
+
var _dec, _dec2, _class;
|
|
180
|
+
let ScopeModuleAStartup = (_dec = Scope(), _dec2 = BeanInfo({
|
|
181
|
+
module: "a-startup"
|
|
182
|
+
}), _dec(_class = _dec2(_class = class ScopeModuleAStartup extends BeanScopeBase {}) || _class) || _class);
|
|
183
|
+
|
|
184
|
+
/** scope: end */
|
|
185
|
+
|
|
186
|
+
function Startup(options) {
|
|
187
|
+
return createBeanDecorator('startup', options);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export { CacheRedisStartupDebounce, MetaRedlock, Monkey, ScopeModuleAStartup, ServiceStartup, Startup, config };
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import type { IInstanceRecord } from 'vona';
|
|
1
2
|
import type { IOnionSlice } from 'vona-module-a-onion';
|
|
2
3
|
import type { IDecoratorStartupOptions, IInstanceStartupOptions } from '../types/startup.ts';
|
|
3
4
|
import { BeanBase } from 'vona';
|
|
4
5
|
export declare class ServiceStartup extends BeanBase {
|
|
5
6
|
appStart(): Promise<void>;
|
|
6
7
|
appReady(): Promise<void>;
|
|
7
|
-
runStartup(startupName: string, instanceName?:
|
|
8
|
-
_runStartupLock(startup: IOnionSlice<IDecoratorStartupOptions>, instanceName?:
|
|
9
|
-
_runStartupInner(startup: IOnionSlice<IDecoratorStartupOptions>, instanceName?:
|
|
10
|
-
runStartupInstance(instanceName:
|
|
8
|
+
runStartup(startupName: string, instanceName?: keyof IInstanceRecord | null, options?: IInstanceStartupOptions): Promise<void>;
|
|
9
|
+
_runStartupLock(startup: IOnionSlice<IDecoratorStartupOptions>, instanceName?: keyof IInstanceRecord | null, options?: IInstanceStartupOptions): Promise<void>;
|
|
10
|
+
_runStartupInner(startup: IOnionSlice<IDecoratorStartupOptions>, instanceName?: keyof IInstanceRecord | null, options?: IInstanceStartupOptions): Promise<void>;
|
|
11
|
+
runStartupInstance(instanceName: keyof IInstanceRecord, options?: IInstanceStartupOptions): Promise<void>;
|
|
11
12
|
private get _startups();
|
|
12
13
|
private _clearResources;
|
|
13
14
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vona-module-a-startup",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.12",
|
|
5
5
|
"title": "a-startup",
|
|
6
6
|
"vonaModule": {
|
|
7
7
|
"dependencies": {},
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"clean": "rimraf dist tsconfig.build.tsbuildinfo",
|
|
45
|
-
"tsc:publish": "npm run clean && tsc -p tsconfig.build.json"
|
|
45
|
+
"tsc:publish": "npm run clean && vona :bin:buildModule && tsc -p tsconfig.build.json"
|
|
46
46
|
}
|
|
47
47
|
}
|
package/dist/.metadata/index.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
/** monkey: end */
|
|
8
|
-
/** scope: begin */
|
|
9
|
-
import { BeanScopeBase } from 'vona';
|
|
10
|
-
/** service: end */
|
|
11
|
-
/** service: begin */
|
|
12
|
-
import { Scope } from 'vona-module-a-bean';
|
|
13
|
-
import 'vona';
|
|
14
|
-
import 'vona';
|
|
15
|
-
import 'vona';
|
|
16
|
-
import 'vona';
|
|
17
|
-
export * from "../bean/cacheRedis.startupDebounce.js";
|
|
18
|
-
/** cacheRedis: end */
|
|
19
|
-
/** meta: begin */
|
|
20
|
-
export * from "../bean/meta.redlock.js";
|
|
21
|
-
/** service: end */
|
|
22
|
-
/** config: begin */
|
|
23
|
-
export * from "../config/config.js";
|
|
24
|
-
/** config: end */
|
|
25
|
-
/** monkey: begin */
|
|
26
|
-
export * from "../monkey.js";
|
|
27
|
-
/** meta redlock: end */
|
|
28
|
-
/** service: begin */
|
|
29
|
-
export * from "../service/startup.js";
|
|
30
|
-
let ScopeModuleAStartup = class ScopeModuleAStartup extends BeanScopeBase {
|
|
31
|
-
};
|
|
32
|
-
ScopeModuleAStartup = __decorate([
|
|
33
|
-
Scope()
|
|
34
|
-
], ScopeModuleAStartup);
|
|
35
|
-
export { ScopeModuleAStartup };
|
|
36
|
-
/** scope: end */
|
package/dist/.metadata/this.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { BeanCacheRedisBase, CacheRedis } from 'vona-module-a-cache';
|
|
8
|
-
let CacheRedisStartupDebounce = class CacheRedisStartupDebounce extends BeanCacheRedisBase {
|
|
9
|
-
};
|
|
10
|
-
CacheRedisStartupDebounce = __decorate([
|
|
11
|
-
CacheRedis()
|
|
12
|
-
], CacheRedisStartupDebounce);
|
|
13
|
-
export { CacheRedisStartupDebounce };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { Meta } from 'vona-module-a-meta';
|
|
8
|
-
import { BeanRedlockBase } from 'vona-module-a-redlock';
|
|
9
|
-
let MetaRedlock = class MetaRedlock extends BeanRedlockBase {
|
|
10
|
-
};
|
|
11
|
-
MetaRedlock = __decorate([
|
|
12
|
-
Meta()
|
|
13
|
-
], MetaRedlock);
|
|
14
|
-
export { MetaRedlock };
|
package/dist/config/config.js
DELETED
package/dist/lib/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./startup.js";
|
package/dist/lib/startup.js
DELETED
package/dist/monkey.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { BeanSimple } from 'vona';
|
|
2
|
-
import { __ThisModule__ } from "./.metadata/this.js";
|
|
3
|
-
export class Monkey extends BeanSimple {
|
|
4
|
-
async appStart() {
|
|
5
|
-
await this.bean.scope(__ThisModule__).service.startup.appStart();
|
|
6
|
-
}
|
|
7
|
-
async appReady() {
|
|
8
|
-
await this.bean.scope(__ThisModule__).service.startup.appReady();
|
|
9
|
-
}
|
|
10
|
-
}
|
package/dist/service/startup.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import path from 'node:path';
|
|
8
|
-
import { isNil } from '@cabloy/utils';
|
|
9
|
-
import fse from 'fs-extra';
|
|
10
|
-
import { BeanBase, cast } from 'vona';
|
|
11
|
-
import { Service } from 'vona-module-a-web';
|
|
12
|
-
let ServiceStartup = class ServiceStartup extends BeanBase {
|
|
13
|
-
async appStart() {
|
|
14
|
-
// clear keys
|
|
15
|
-
await this._clearResources();
|
|
16
|
-
// run startups: not after
|
|
17
|
-
for (const startup of this._startups) {
|
|
18
|
-
const startupOptions = startup.beanOptions.options;
|
|
19
|
-
if (!startupOptions?.instance && startupOptions?.after !== true) {
|
|
20
|
-
await this.runStartup(startup.name, null);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
async appReady() {
|
|
25
|
-
// run startups: after
|
|
26
|
-
for (const startup of this._startups) {
|
|
27
|
-
const startupOptions = startup.beanOptions.options;
|
|
28
|
-
if (!startupOptions?.instance && startupOptions?.after === true) {
|
|
29
|
-
await this.runStartup(startup.name, null);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
// version init : force: should be false
|
|
33
|
-
if (this.app.meta.isTest || this.app.meta.isLocal) {
|
|
34
|
-
const instanceName = '';
|
|
35
|
-
await this.bean.executor.newCtx(async () => {
|
|
36
|
-
await this.$scope.instance.service.instance.instanceStartup(instanceName, { force: false });
|
|
37
|
-
}, {
|
|
38
|
-
dbInfo: true,
|
|
39
|
-
instanceName,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
// all instances
|
|
44
|
-
const instances = await this.bean.executor.newCtx(async () => {
|
|
45
|
-
return await this.bean.instance.list();
|
|
46
|
-
}, { dbInfo: true });
|
|
47
|
-
for (const instance of instances) {
|
|
48
|
-
const instanceName = instance.name;
|
|
49
|
-
// need not await
|
|
50
|
-
this.bean.executor.newCtx(async () => {
|
|
51
|
-
await this.$scope.instance.service.instance.instanceStartup(instanceName, { force: false });
|
|
52
|
-
}, {
|
|
53
|
-
dbInfo: true,
|
|
54
|
-
instanceName,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// version test
|
|
59
|
-
if (this.app.meta.isTest) {
|
|
60
|
-
const instanceName = '';
|
|
61
|
-
await this.bean.executor.newCtx(async () => {
|
|
62
|
-
await this.$scope.version.service.version.__instanceTest(instanceName);
|
|
63
|
-
}, {
|
|
64
|
-
dbInfo: true,
|
|
65
|
-
instanceName,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
async runStartup(startupName, instanceName, options) {
|
|
70
|
-
const startup = this.bean.onion.startup.onionsNormal[startupName];
|
|
71
|
-
const startupOptions = startup.beanOptions.options;
|
|
72
|
-
// normal
|
|
73
|
-
if (!startupOptions.debounce) {
|
|
74
|
-
return await this._runStartupInner(startup, instanceName, options);
|
|
75
|
-
}
|
|
76
|
-
// debounce: lock
|
|
77
|
-
return await this.scope.redlock.lockIsolate(`startup.${startupName}`, async () => {
|
|
78
|
-
return await this._runStartupLock(startup, instanceName, options);
|
|
79
|
-
}, {
|
|
80
|
-
instanceName,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
async _runStartupLock(startup, instanceName, options) {
|
|
84
|
-
// ignore debounce for test
|
|
85
|
-
if (!options?.force && !this.app.meta.isTest) {
|
|
86
|
-
const startupOptions = startup.beanOptions.options;
|
|
87
|
-
const cacheKey = `startupDebounce:${startup.name}${!isNil(instanceName) ? `:${this.ctx.instance.id}` : ''}`;
|
|
88
|
-
const debounce = typeof startupOptions.debounce === 'number' ? startupOptions.debounce : this.scope.config.startup.debounce;
|
|
89
|
-
const flag = await this.scope.cacheRedis.startupDebounce.getset(true, cacheKey, { ttl: debounce });
|
|
90
|
-
if (flag)
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
// perform
|
|
94
|
-
await this._runStartupInner(startup, instanceName, options);
|
|
95
|
-
}
|
|
96
|
-
async _runStartupInner(startup, instanceName, options) {
|
|
97
|
-
this.$logger.silly(`startup${startup.beanOptions?.options?.instance ? ' instance' : ''}: ${startup.name}, pid: ${process.pid}`);
|
|
98
|
-
const startupOptions = startup.beanOptions.options;
|
|
99
|
-
// execute
|
|
100
|
-
return await this.bean.executor.newCtx(async () => {
|
|
101
|
-
const bean = cast(this.bean._getBean(startup.beanOptions.beanFullName));
|
|
102
|
-
await bean.execute(options);
|
|
103
|
-
}, {
|
|
104
|
-
dbInfo: true,
|
|
105
|
-
instanceName,
|
|
106
|
-
transaction: startupOptions.transaction,
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
async runStartupInstance(instanceName, options) {
|
|
110
|
-
// run startups: not after
|
|
111
|
-
for (const startup of this._startups) {
|
|
112
|
-
const startupOptions = startup.beanOptions.options;
|
|
113
|
-
if (startupOptions?.instance && startupOptions?.after !== true) {
|
|
114
|
-
await this.runStartup(startup.name, instanceName, options);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
// set flag
|
|
118
|
-
this.app.meta.appReadyInstances[instanceName] = true;
|
|
119
|
-
// run startups: after
|
|
120
|
-
for (const startup of this._startups) {
|
|
121
|
-
const startupOptions = startup.beanOptions.options;
|
|
122
|
-
if (startupOptions?.instance && startupOptions?.after === true) {
|
|
123
|
-
await this.runStartup(startup.name, instanceName, options);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
get _startups() {
|
|
128
|
-
return this.bean.onion.startup.getOnionsEnabled();
|
|
129
|
-
}
|
|
130
|
-
async _clearResources() {
|
|
131
|
-
if (!this.app.meta.isTest)
|
|
132
|
-
return;
|
|
133
|
-
// redis
|
|
134
|
-
await this.$scope.redis.service.redisClient.clearAllData();
|
|
135
|
-
// .app/public
|
|
136
|
-
await fse.remove(path.join(this.app.config.server.publicDir, '1'));
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
ServiceStartup = __decorate([
|
|
140
|
-
Service()
|
|
141
|
-
], ServiceStartup);
|
|
142
|
-
export { ServiceStartup };
|
package/dist/types/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./startup.js";
|
package/dist/types/startup.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|