@thzero/library_server 0.18.10 → 0.18.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/boot/index.js CHANGED
@@ -2,7 +2,7 @@ import { createTerminus } from '@godaddy/terminus';
2
2
 
3
3
  import config from 'config';
4
4
 
5
- import {internalIpV4} from '@thzero/library_server/utility/internalIp/index.js';
5
+ import { internalIpV4 } from '@thzero/library_server/utility/internalIp/index.js';
6
6
 
7
7
  import LibraryServerConstants from '../constants.js';
8
8
  import LibraryCommonServiceConstants from '@thzero/library_common_service/constants.js';
@@ -75,6 +75,7 @@ class BootMain {
75
75
  // https://github.com/lorenwest/node-config/wiki
76
76
  this._appConfig = new configService(config.get('app'));
77
77
 
78
+ this._repositoriesPost = new Map();
78
79
  this._servicesPost = new Map();
79
80
 
80
81
  const plugins = this._determinePlugins(args);
@@ -90,17 +91,23 @@ class BootMain {
90
91
 
91
92
  const results = await this._initApp(args, plugins);
92
93
 
93
- function onSignal() {
94
- this.loggerServiceI.info2(`server is starting cleanup`);
94
+ async function onSignal() {
95
+ console.log('server is starting cleanup');
96
+ this.loggerServiceI.info2('server is starting cleanup');
95
97
  const cleanupFuncs = [];
96
98
  this._initCleanup(cleanupFuncs);
97
99
  this._initCleanupDiscovery(cleanupFuncs);
98
- return Promise.all(cleanupFuncs);
100
+ await Promise.all(cleanupFuncs);
101
+ console.log('server is starting cleanup completed');
102
+ this.loggerServiceI.info2('server is starting cleanup completed');
99
103
  }
100
104
 
101
- function onShutdown() {
105
+ async function onShutdown() {
106
+ console.log('server is shutting down');
107
+ this.loggerServiceI.info2('server is shutting down');
102
108
  this._initShutdown();
103
- this.loggerServiceI.info2(`cleanup finished, server is shutting down`);
109
+ console.log('server is shutting down completed');
110
+ this.loggerServiceI.info2('server is shutting down completed');
104
111
  }
105
112
 
106
113
  function healthCheck() {
@@ -129,7 +136,7 @@ class BootMain {
129
136
  healthChecks: healthCheckOptions,
130
137
 
131
138
  // cleanup options
132
- signals: [ 'SIGINT', 'SIGTERM' ],
139
+ signals: [ 'SIGINT', 'SIGTERM', 'SIGQUIT', 'SIGKILL' ],
133
140
  onSignal: onSignal.bind(this), // [optional] cleanup function, returning a promise (used to be onSigterm)
134
141
  onShutdown: onShutdown.bind(this) // [optional] called right before exiting
135
142
  };
@@ -153,15 +160,39 @@ class BootMain {
153
160
  // this.address = await internalIpV4();
154
161
 
155
162
  await this._initServer(results.server);
163
+
164
+ console.log('----repositories.init.post-------------');
165
+
166
+ for (const [key, value] of this._repositoriesPost) {
167
+ if (value.initPost) {
168
+ console.log(`repositories.init.post - ${key}`);
169
+ await value.initPost();
170
+ }
171
+ }
172
+
173
+ console.log('----repositories.init.post.complete----');
174
+ console.log();
175
+
176
+ console.log('----services.init.post-----------------');
156
177
 
157
178
  for (const [key, value] of this._servicesPost) {
158
- console.log(`services.init.post - ${key}`);
159
- if (value.initPost)
179
+ if (value.initPost) {
180
+ console.log(`services.init.post - ${key}`);
160
181
  await value.initPost();
182
+ }
161
183
  }
162
- this._initAppPost(results.app, args);
184
+
185
+ console.log('----services.init.post.complete--------');
186
+ console.log();
187
+
188
+ console.log('----services.init.app.post-------------');
163
189
 
190
+ this._initAppPost(results.app, args);
191
+
192
+ console.log('----services.init.app.post.complete----');
164
193
  console.log();
194
+
195
+ console.log('----server.startup.config--------------');
165
196
  this.ip = this._appConfig.get('ip', null);
166
197
  console.log(`config.ip.override: ${this.ip}`);
167
198
  this.port = this._appConfig.get('port');
@@ -169,14 +200,13 @@ class BootMain {
169
200
  console.log(`process.env.PORT: ${process.env.PORT}`);
170
201
  this.port = process.env.PORT || this.port;
171
202
  console.log(`selected.port: ${this.port}`);
172
- console.log();
173
203
 
174
204
  const self = this;
175
205
  const listen = async (port, address) => new Promise((resolve, reject) => {
176
206
  self._initAppListen(results.app, results.server, address, port, (err) => {
177
207
  if (err) {
178
208
  reject(err);
179
- return;
209
+ process.exit(1);
180
210
  }
181
211
 
182
212
  resolve();
@@ -190,6 +220,9 @@ class BootMain {
190
220
  console.log();
191
221
  console.log(`Starting HTTP on: ${this.address}:${this.port}`);
192
222
 
223
+ console.log('----server.startup.config.complete-----');
224
+ console.log();
225
+
193
226
  await this._initServerDiscovery();
194
227
 
195
228
  await this._initServerStart(injector);
@@ -241,14 +274,21 @@ class BootMain {
241
274
 
242
275
  this._repositories = new Map();
243
276
 
277
+ console.log();
278
+ console.log('----repository.injection-------------------------');
244
279
  for (const pluginRepository of plugins)
245
280
  await pluginRepository.initRepositories(this._repositories);
246
281
 
247
282
  await this._initRepositories();
283
+
248
284
  this._injectRepository(LibraryServerConstants.InjectorKeys.REPOSITORY_USAGE_METRIC, this._initRepositoriesUsageMetrics());
249
285
 
286
+ console.log('----repository.injection.complete----------------');
287
+ console.log();
288
+
250
289
  this._services = new Map();
251
290
 
291
+ console.log('----services.injection---------------------------');
252
292
  this.loggerServiceI = this._initServicesLogger();
253
293
  this._initServicesLoggers();
254
294
  this._injectService(LibraryCommonServiceConstants.InjectorKeys.SERVICE_LOGGER, this.loggerServiceI);
@@ -274,11 +314,21 @@ class BootMain {
274
314
 
275
315
  await this._initServices();
276
316
 
317
+ console.log('----services.injection.complete------------------');
318
+ console.log();
319
+
320
+ console.log('----repositories.injection.init------------------');
277
321
  for (const [key, value] of this._repositories) {
278
322
  console.log(`repositories.init - ${key}`);
279
323
  await value.init(injector);
324
+
325
+ this._repositoriesPost.set(key, value);
280
326
  }
281
327
 
328
+ console.log('----repositories.injection.init.complete---------');
329
+ console.log();
330
+
331
+ console.log('----services.injection.init----------------------');
282
332
  for (const [key, value] of this._services) {
283
333
  console.log(`services.init - ${key}`);
284
334
  await value.init(injector);
@@ -286,13 +336,22 @@ class BootMain {
286
336
  this._servicesPost.set(key, value);
287
337
  }
288
338
 
339
+ console.log('----services.injection.init.complete-------------');
340
+ console.log();
341
+
289
342
  this._services = new Map();
290
343
 
344
+ console.log('----services.injection.secondary-----------------');
291
345
  await this._initServicesSecondary();
292
346
 
293
347
  for (const pluginService of plugins)
294
348
  await pluginService.initServicesSecondary(this._services);
295
349
 
350
+ console.log('----services.injection.secondary.complete--------');
351
+ console.log();
352
+
353
+ console.log('----services.injection.initsecondary-------------');
354
+
296
355
  for (const [key, value] of this._services) {
297
356
  if (value.initialized)
298
357
  continue;
@@ -303,6 +362,9 @@ class BootMain {
303
362
  this._servicesPost.set(key, value);
304
363
  }
305
364
 
365
+ console.log('----services.injection.initsecondary.complete----');
366
+ console.log();
367
+
306
368
  LibraryMomentUtility.initDateTime();
307
369
  }
308
370
  finally {
@@ -435,17 +497,7 @@ class BootMain {
435
497
  await this.resourceDiscoveryServiceI.initializeDiscovery(await this._initServerDiscoveryOptsResources(opts));
436
498
  }
437
499
 
438
- async _initServerStart() {
439
- for(const service of injector.getServices()) {
440
- if (service.dependency) {
441
- if (service.dependency && service.dependency.initialize) {
442
- if (service.dependency.initialize.length === 0) {
443
- console.log(`services.initialize - ${service.key}`);
444
- await service.dependency.initialize();
445
- }
446
- }
447
- }
448
- }
500
+ async _initServerStart(injector) {
449
501
  }
450
502
 
451
503
  _injectRepository(key, repository) {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@thzero/library_server",
3
3
  "type": "module",
4
- "version": "0.18.10",
4
+ "version": "0.18.12",
5
5
  "version_major": 0,
6
6
  "version_minor": 18,
7
- "version_patch": 10,
8
- "version_date": "04/23/2024",
7
+ "version_patch": 12,
8
+ "version_date": "05/01/2024",
9
9
  "description": "An opinionated library of common functionality to bootstrap an API using either Fastify or Koa as the web server.",
10
10
  "author": "thZero",
11
11
  "license": "MIT",
@@ -129,7 +129,8 @@ class UtilityService extends Service {
129
129
  const dir = path.join(path.resolve(__dirname), 'node_modules', '@thzero');
130
130
  const dirs = await fs.promises.readdir(dir);
131
131
 
132
- console.log(`\tOpenSource...`);
132
+ console.log();
133
+ console.log('\t----open.source.initialization-----------------');
133
134
 
134
135
  let file;
135
136
  let importPath;
@@ -145,7 +146,7 @@ class UtilityService extends Service {
145
146
  }
146
147
 
147
148
  importPath = ['@thzero', item, 'openSource.js'].join('/');
148
- console.log(`\t${importPath}...`);
149
+ console.log(`\t\t${importPath}...`);
149
150
  fileI = await import(importPath);
150
151
  if (!fileI.default) {
151
152
  console.log(`\t...failed to load.`);
@@ -172,7 +173,8 @@ class UtilityService extends Service {
172
173
  this._logger.warn('UtilityService', '_initializeOopenSource', null, err, correlationId);
173
174
  }
174
175
  finally {
175
- console.log(`\t...OpenSource`);
176
+ console.log('\t----open.source.initialization.complete--------');
177
+ console.log();
176
178
  }
177
179
 
178
180
  // response.results = await this._openSourceServer(correlationId);