@steedos/service-package-loader 2.2.54-beta.4 → 2.2.54-beta.7

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.
Files changed (2) hide show
  1. package/index.js +45 -20
  2. package/package.json +5 -5
package/index.js CHANGED
@@ -45,22 +45,13 @@ module.exports = {
45
45
  */
46
46
  events: {
47
47
  "steedos-server.started": {
48
- handler() {
49
- let packageInfo = this.settings.packageInfo;
50
- if (!packageInfo) {
51
- return;
52
- }
53
- const { path : _path } = packageInfo;
54
-
55
- this.loadPackagePublicFiles(_path);
56
-
57
- if(_path){
58
- //此处延迟10秒加载流程文件,防止工作区初始化未完成
59
- setTimeout(() => {
60
- sendPackageFlowToDb(this.broker, _path)
61
- processLoader.sendPackageProcessToDb(_path);
62
- }, 10 * 1000)
63
- }
48
+ async handler() {
49
+ await this.loadDataOnServiceStarted();
50
+ }
51
+ },
52
+ "space.initialized": {
53
+ async handler() {
54
+ await this.loadDataOnServiceStarted();
64
55
  }
65
56
  }
66
57
  },
@@ -69,6 +60,19 @@ module.exports = {
69
60
  * Methods
70
61
  */
71
62
  methods: {
63
+ loadDataOnServiceStarted: async function(){
64
+ let packageInfo = this.settings.packageInfo;
65
+ if (!packageInfo) {
66
+ return;
67
+ }
68
+ const { path : _path } = packageInfo;
69
+
70
+ this.loadPackagePublicFiles(_path);
71
+ if(_path){
72
+ sendPackageFlowToDb(this.broker, _path)
73
+ processLoader.sendPackageProcessToDb(_path);
74
+ }
75
+ },
72
76
  loadPackageMetadataFiles: async function (packagePath, name, datasourceName) {
73
77
  this.broker.logger.debug(`Loading package from ${packagePath}`)
74
78
  await Future.task(async () => {
@@ -151,6 +155,13 @@ module.exports = {
151
155
  this.settings.loadedPackagePublicFiles = false;
152
156
  }
153
157
  }
158
+ },
159
+ async errorHandler(error) {
160
+ this.broker.logger.error(`[${this.name}] 启动失败: ${error.message}`);
161
+ await await this.broker.call(`~packages-project-server.disablePackage`, {
162
+ module: this.schema.packageName
163
+ })
164
+ return await this.broker.destroyService(this);
154
165
  }
155
166
  },
156
167
 
@@ -163,6 +174,7 @@ module.exports = {
163
174
  },
164
175
 
165
176
  merged(schema) {
177
+ schema.packageName = schema.name;
166
178
  schema.name = `~packages-${schema.name}`;
167
179
  },
168
180
 
@@ -170,6 +182,14 @@ module.exports = {
170
182
  * Service started lifecycle event handler
171
183
  */
172
184
  async started() {
185
+ if(this.beforeStart){
186
+ try {
187
+ await this.beforeStart()
188
+ } catch (error) {
189
+ return await this.errorHandler(error);
190
+ }
191
+ }
192
+
173
193
  console.time(`service ${this.name} started`)
174
194
  let packageInfo = this.settings.packageInfo;
175
195
  if (!packageInfo) {
@@ -182,8 +202,7 @@ module.exports = {
182
202
  return;
183
203
  }
184
204
  this.broker.waitForServices("steedos-server").then(async () => {
185
- sendPackageFlowToDb(this.broker, _path, this.name)
186
- processLoader.sendPackageProcessToDb(_path);
205
+ await this.loadDataOnServiceStarted()
187
206
  });
188
207
 
189
208
  await this.loadPackageMetadataFiles(_path, this.name, datasource);
@@ -198,10 +217,16 @@ module.exports = {
198
217
 
199
218
  await this.loadPackageMetadataServices(_path);
200
219
 
201
- await this.loadPackagePublicFiles(_path);
220
+ // await this.loadPackagePublicFiles(_path);
202
221
  this.started = true;
203
222
  console.timeEnd(`service ${this.name} started`)
204
- // console.log(`service ${this.name} started`);
223
+ if(this.afterStart){
224
+ try {
225
+ await this.afterStart();
226
+ } catch (error) {
227
+ this.broker.logger.error(`[${this.name}]: ${error.message}`);
228
+ }
229
+ }
205
230
  },
206
231
 
207
232
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-package-loader",
3
- "version": "2.2.54-beta.4",
3
+ "version": "2.2.54-beta.7",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -10,9 +10,9 @@
10
10
  "author": "",
11
11
  "license": "MIT",
12
12
  "dependencies": {
13
- "@steedos/core": "2.2.54-beta.4",
14
- "@steedos/metadata-core": "2.2.54-beta.4",
15
- "@steedos/objectql": "2.2.54-beta.4",
13
+ "@steedos/core": "2.2.54-beta.7",
14
+ "@steedos/metadata-core": "2.2.54-beta.7",
15
+ "@steedos/objectql": "2.2.54-beta.7",
16
16
  "clone": "^2.1.2",
17
17
  "globby": "^11.1.0",
18
18
  "moleculer": "^0.14.21",
@@ -25,5 +25,5 @@
25
25
  "publishConfig": {
26
26
  "access": "public"
27
27
  },
28
- "gitHead": "f68c327098f378d5e3d8dc5b12508e31ad368947"
28
+ "gitHead": "1de03714622c2de137a7a51623e94bb7df45f204"
29
29
  }