tnp-helpers 19.0.65 → 19.0.66
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/browser/README.md +24 -24
- package/browser/fesm2022/tnp-helpers.mjs +3032 -256
- package/browser/fesm2022/tnp-helpers.mjs.map +1 -1
- package/browser/lib/base/classes/base-cli-worker/base-cli-worker-controller.d.ts +3 -4
- package/browser/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.d.ts +1 -1
- package/browser/lib/base/classes/base-cli-worker/base-cli-worker.d.ts +59 -35
- package/browser/lib/base/classes/base-cli-worker/base-cli-worker.models.d.ts +42 -0
- package/browser/lib/base/classes/base-cli-worker/base-cli-worker.utils.d.ts +4 -0
- package/browser/lib/base/classes/base-cli-worker/index.d.ts +1 -0
- package/browser/lib/base/classes/base-docker.d.ts +1 -0
- package/browser/lib/base/classes/base-git.d.ts +2 -0
- package/browser/lib/base/classes/base-global-command-line.d.ts +254 -0
- package/browser/lib/base/classes/base-npm-helpers.d.ts +1 -0
- package/browser/lib/base/classes/base-release-process.d.ts +3 -1
- package/browser/lib/base/classes/index.d.ts +2 -1
- package/browser/lib/base/gh-temp-code.d.ts +17 -0
- package/browser/lib/build-info._auto-generated_.d.ts +1 -1
- package/browser/lib/utils.d.ts +3 -40
- package/browser/package.json +1 -1
- package/lib/base/classes/base-cli-worker/base-cli-worker-controller.d.ts +3 -4
- package/lib/base/classes/base-cli-worker/base-cli-worker-controller.js +28 -15
- package/lib/base/classes/base-cli-worker/base-cli-worker-controller.js.map +1 -1
- package/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.d.ts +1 -1
- package/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.js +10 -6
- package/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.js.map +1 -1
- package/lib/base/classes/base-cli-worker/base-cli-worker.d.ts +57 -33
- package/lib/base/classes/base-cli-worker/base-cli-worker.js +326 -213
- package/lib/base/classes/base-cli-worker/base-cli-worker.js.map +1 -1
- package/lib/base/classes/base-cli-worker/base-cli-worker.models.d.ts +41 -0
- package/lib/base/classes/base-cli-worker/base-cli-worker.models.js +34 -0
- package/lib/base/classes/base-cli-worker/base-cli-worker.models.js.map +1 -0
- package/lib/base/classes/base-cli-worker/base-cli-worker.utils.d.ts +3 -0
- package/lib/base/classes/base-cli-worker/base-cli-worker.utils.js +19 -0
- package/lib/base/classes/base-cli-worker/base-cli-worker.utils.js.map +1 -0
- package/lib/base/classes/base-cli-worker/index.d.ts +1 -0
- package/lib/base/classes/base-cli-worker/index.js +1 -0
- package/lib/base/classes/base-cli-worker/index.js.map +1 -1
- package/lib/base/classes/base-command-line-feature.backend.d.ts +47 -0
- package/lib/base/classes/base-command-line-feature.backend.js +147 -0
- package/lib/base/classes/base-command-line-feature.backend.js.map +1 -0
- package/lib/base/classes/base-docker.d.ts +1 -0
- package/lib/base/classes/base-docker.js +7 -0
- package/lib/base/classes/base-docker.js.map +1 -1
- package/lib/base/classes/base-git.d.ts +2 -0
- package/lib/base/classes/base-git.js +6 -1
- package/lib/base/classes/base-git.js.map +1 -1
- package/lib/base/classes/base-global-command-line.backend.d.ts +1 -0
- package/lib/base/classes/base-global-command-line.backend.js +55 -62
- package/lib/base/classes/base-global-command-line.backend.js.map +1 -1
- package/lib/base/classes/base-global-command-line.d.ts +260 -0
- package/lib/base/classes/base-global-command-line.js +2406 -0
- package/lib/base/classes/base-global-command-line.js.map +1 -0
- package/lib/base/classes/base-npm-helpers.d.ts +1 -0
- package/lib/base/classes/base-npm-helpers.js +1 -1
- package/lib/base/classes/base-npm-helpers.js.map +1 -1
- package/lib/base/classes/base-project-resolver.js +2 -1
- package/lib/base/classes/base-project-resolver.js.map +1 -1
- package/lib/base/classes/base-project.js +8 -6
- package/lib/base/classes/base-project.js.map +1 -1
- package/lib/base/classes/base-release-process.d.ts +3 -1
- package/lib/base/classes/base-release-process.js +4 -3
- package/lib/base/classes/base-release-process.js.map +1 -1
- package/lib/base/classes/index.d.ts +1 -1
- package/lib/base/classes/index.js +2 -4
- package/lib/base/classes/index.js.map +1 -1
- package/lib/base/tcp-udp-ports/not-assignable-port.entity.js +2 -2
- package/lib/base/tcp-udp-ports/ports.entity.d.ts +1 -1
- package/lib/base/tcp-udp-ports/tcp-upd-ports-terminal-ui.js +27 -14
- package/lib/base/tcp-udp-ports/tcp-upd-ports-terminal-ui.js.map +1 -1
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/helpers/for-backend/helpers-dependencies.backend.d.ts +3 -0
- package/lib/helpers/for-backend/helpers-dependencies.backend.js +34 -0
- package/lib/helpers/for-backend/helpers-dependencies.backend.js.map +1 -0
- package/lib/helpers/for-backend/helpers-git.backend.d.ts +1 -0
- package/lib/helpers/for-backend/helpers-git.backend.js +46 -17
- package/lib/helpers/for-backend/helpers-git.backend.js.map +1 -1
- package/lib/helpers/for-browser/angular.helper.js +2 -2
- package/lib/helpers/helpers-numbers.js.map +1 -1
- package/lib/old/base-component.js +2 -2
- package/lib/old/base-formly-component.js +2 -2
- package/lib/old/dual-component-ctrl.js +2 -2
- package/lib/utils.d.ts +3 -40
- package/lib/utils.js +34 -111
- package/lib/utils.js.map +1 -1
- package/lib/validators/validators-firedev.d.ts +3 -0
- package/lib/validators/validators-firedev.js +34 -0
- package/lib/validators/validators-firedev.js.map +1 -0
- package/lib/validators/validators-git.d.ts +3 -0
- package/lib/validators/validators-git.js +13 -0
- package/lib/validators/validators-git.js.map +1 -0
- package/lib/validators/validators-network.d.ts +3 -0
- package/lib/validators/validators-network.js +19 -0
- package/lib/validators/validators-network.js.map +1 -0
- package/lib/validators/validators.d.ts +6 -0
- package/lib/validators/validators.js +11 -0
- package/lib/validators/validators.js.map +1 -0
- package/package.json +1 -1
- package/tmp-environment.json +37 -0
- package/websql/README.md +24 -24
- package/websql/fesm2022/tnp-helpers.mjs +3032 -256
- package/websql/fesm2022/tnp-helpers.mjs.map +1 -1
- package/websql/lib/base/classes/base-cli-worker/base-cli-worker-controller.d.ts +3 -4
- package/websql/lib/base/classes/base-cli-worker/base-cli-worker-terminal-ui.d.ts +1 -1
- package/websql/lib/base/classes/base-cli-worker/base-cli-worker.d.ts +59 -35
- package/websql/lib/base/classes/base-cli-worker/base-cli-worker.models.d.ts +42 -0
- package/websql/lib/base/classes/base-cli-worker/base-cli-worker.utils.d.ts +4 -0
- package/websql/lib/base/classes/base-cli-worker/index.d.ts +1 -0
- package/websql/lib/base/classes/base-docker.d.ts +1 -0
- package/websql/lib/base/classes/base-git.d.ts +2 -0
- package/websql/lib/base/classes/base-global-command-line.d.ts +254 -0
- package/websql/lib/base/classes/base-npm-helpers.d.ts +1 -0
- package/websql/lib/base/classes/base-release-process.d.ts +3 -1
- package/websql/lib/base/classes/index.d.ts +2 -1
- package/websql/lib/base/gh-temp-code.d.ts +17 -0
- package/websql/lib/build-info._auto-generated_.d.ts +1 -1
- package/websql/lib/utils.d.ts +3 -40
- package/websql/package.json +1 -1
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseCliWorker = void 0;
|
|
4
|
-
const lib_1 = require("tnp-
|
|
4
|
+
const lib_1 = require("tnp-config/lib");
|
|
5
|
+
const lib_2 = require("tnp-core/lib");
|
|
5
6
|
const index_1 = require("../../../index");
|
|
6
7
|
const base_cli_worker_config_1 = require("./base-cli-worker-config");
|
|
7
8
|
const base_cli_worker_terminal_ui_1 = require("./base-cli-worker-terminal-ui");
|
|
9
|
+
const base_cli_worker_models_1 = require("./base-cli-worker.models");
|
|
10
|
+
const base_cli_worker_utils_1 = require("./base-cli-worker.utils");
|
|
8
11
|
//#endregion
|
|
9
12
|
//#region constants
|
|
10
13
|
const WORKER_INIT_START_TIME_LIMIT = 25; // 15 seconds max to start worker
|
|
@@ -15,52 +18,15 @@ class BaseCliWorker {
|
|
|
15
18
|
startCommand;
|
|
16
19
|
serviceVersion;
|
|
17
20
|
//#region fields & getters
|
|
18
|
-
SPECIAL_WORKER_READY_MESSAGE =
|
|
21
|
+
SPECIAL_WORKER_READY_MESSAGE = lib_2.CoreModels.SPECIAL_WORKER_READY_MESSAGE;
|
|
22
|
+
/**
|
|
23
|
+
* dependency workers that should be started before this worker
|
|
24
|
+
*/
|
|
25
|
+
dependencyWorkers = new Map();
|
|
19
26
|
// @ts-ignore TODO weird inheritance problem
|
|
20
27
|
terminalUI = new base_cli_worker_terminal_ui_1.BaseCliWorkerTerminalUI(this);
|
|
21
28
|
workerContextTemplate;
|
|
22
|
-
workerMainContext;
|
|
23
|
-
// private workerRemoteContextFor: {
|
|
24
|
-
// [ipAddressOfTaonInstance: string]: ReturnType<typeof Taon.createContext>;
|
|
25
|
-
// } = {};
|
|
26
|
-
async getRemoteControllerFor(ipAddressOfTaonInstance, port) {
|
|
27
|
-
// this.workerRemoteContextFor[ipAddressOfTaonInstance] = remoteCtx;
|
|
28
|
-
const useHttps = ipAddressOfTaonInstance !== lib_1.CoreModels.localhostIp127;
|
|
29
|
-
const protocol = useHttps ? 'https' : 'http';
|
|
30
|
-
const remoteCtx = this.workerContextTemplate().cloneAsRemote({
|
|
31
|
-
overrideRemoteHost: `${protocol}://${ipAddressOfTaonInstance}${port ? `:${port}` : ''}`,
|
|
32
|
-
});
|
|
33
|
-
const contextForRemoteConnection = await remoteCtx.initialize();
|
|
34
|
-
const taonProjectsController = contextForRemoteConnection.getInstanceBy(this.controllerClass);
|
|
35
|
-
return taonProjectsController;
|
|
36
|
-
}
|
|
37
|
-
workerRemoteContext;
|
|
38
29
|
controllerClass;
|
|
39
|
-
contextForRemoteConnection;
|
|
40
|
-
//#region fields & getters / path to process local info
|
|
41
|
-
get pathToProcessLocalInfoJson() {
|
|
42
|
-
//#region @backendFunc
|
|
43
|
-
// console.log('os.userInfo()', os.userInfo());
|
|
44
|
-
return (0, lib_1.crossPlatformPath)([
|
|
45
|
-
lib_1.UtilsOs.getRealHomeDir(),
|
|
46
|
-
`.taon`,
|
|
47
|
-
'__workers-service-process-info__',
|
|
48
|
-
`${this.serviceID}.json`,
|
|
49
|
-
]);
|
|
50
|
-
//#endregion
|
|
51
|
-
}
|
|
52
|
-
//#endregion
|
|
53
|
-
//#region fields & getters / process local info json object
|
|
54
|
-
get processLocalInfoObj() {
|
|
55
|
-
//#region @backendFunc
|
|
56
|
-
const configJson = index_1.Helpers.readJson5(this.pathToProcessLocalInfoJson) || {};
|
|
57
|
-
if (lib_1._.isObject(configJson)) {
|
|
58
|
-
return lib_1._.merge(new base_cli_worker_config_1.BaseCliWorkerConfig(), configJson);
|
|
59
|
-
}
|
|
60
|
-
return new base_cli_worker_config_1.BaseCliWorkerConfig();
|
|
61
|
-
//#endregion
|
|
62
|
-
}
|
|
63
|
-
//#endregion
|
|
64
30
|
//#endregion
|
|
65
31
|
//#region constructor
|
|
66
32
|
constructor(
|
|
@@ -81,83 +47,27 @@ class BaseCliWorker {
|
|
|
81
47
|
this.serviceVersion = serviceVersion;
|
|
82
48
|
}
|
|
83
49
|
//#endregion
|
|
84
|
-
//#region
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
* for production use startDetachedIfNeedsToBeStarted()
|
|
88
|
-
* start normally process
|
|
89
|
-
* this will crash if process already started
|
|
90
|
-
*/
|
|
91
|
-
async startNormallyInCurrentProcess(options) {
|
|
50
|
+
//#region public
|
|
51
|
+
//#region public fields & getters / process local info json object
|
|
52
|
+
get processLocalInfoObj() {
|
|
92
53
|
//#region @backendFunc
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
await this.preventStartIfAlreadyStarted();
|
|
97
|
-
const port = await this.getServicePort();
|
|
98
|
-
this.workerMainContext = this.workerContextTemplate().cloneAsNormal({
|
|
99
|
-
overrideHost: `http://localhost:${port}`,
|
|
100
|
-
});
|
|
101
|
-
await this.workerMainContext.initialize();
|
|
102
|
-
await this.initializeWorkerMetadata();
|
|
103
|
-
index_1.Helpers.info(`Service started !`);
|
|
104
|
-
this.preventExternalConfigChange();
|
|
105
|
-
if (lib_1._.isFunction(options.actionBeforeTerminalUI)) {
|
|
106
|
-
await options.actionBeforeTerminalUI();
|
|
54
|
+
const configJson = index_1.Helpers.readJson5(this.pathToProcessLocalInfoJson) || {};
|
|
55
|
+
if (lib_2._.isObject(configJson)) {
|
|
56
|
+
return lib_2._.merge(new base_cli_worker_config_1.BaseCliWorkerConfig(), configJson);
|
|
107
57
|
}
|
|
108
|
-
|
|
109
|
-
await this.terminalUI.infoScreen();
|
|
58
|
+
return new base_cli_worker_config_1.BaseCliWorkerConfig();
|
|
110
59
|
//#endregion
|
|
111
60
|
}
|
|
112
61
|
//#endregion
|
|
113
|
-
//#region methods / get
|
|
114
|
-
async
|
|
115
|
-
//#region @backendFunc
|
|
62
|
+
//#region public methods / get remote controller
|
|
63
|
+
async getRemoteControllerFor(options) {
|
|
116
64
|
options = options || {};
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (this.contextForRemoteConnection &&
|
|
123
|
-
!lib_1._.isNaN(this.contextForRemoteConnection.port) &&
|
|
124
|
-
!lib_1._.isNaN(this.processLocalInfoObj.port) &&
|
|
125
|
-
this.contextForRemoteConnection.port !== this.processLocalInfoObj.port) {
|
|
126
|
-
index_1.Helpers.logInfo('Destroying old context for remote connection...');
|
|
127
|
-
// debugger;
|
|
128
|
-
await this.contextForRemoteConnection.destroy();
|
|
129
|
-
delete this.contextForRemoteConnection;
|
|
130
|
-
}
|
|
131
|
-
if (!this.contextForRemoteConnection) {
|
|
132
|
-
index_1.Helpers.logInfo('Creating new context for remote connection...');
|
|
133
|
-
this.workerRemoteContext = this.workerContextTemplate().cloneAsRemote({
|
|
134
|
-
overrideRemoteHost: `http://localhost:${this.processLocalInfoObj.port}`,
|
|
135
|
-
});
|
|
136
|
-
this.contextForRemoteConnection =
|
|
137
|
-
await this.workerRemoteContext.initialize();
|
|
138
|
-
}
|
|
139
|
-
const taonProjectsController = this.contextForRemoteConnection.getInstanceBy(this.controllerClass);
|
|
65
|
+
options.methodOptions = base_cli_worker_models_1.BaseCliMethodOptions.from(options.methodOptions);
|
|
66
|
+
const remoteEndpointContext = await this.getRemoteContextFor(options);
|
|
67
|
+
const taonProjectsController = remoteEndpointContext.getInstanceBy(options.controllerClass
|
|
68
|
+
? options.controllerClass
|
|
69
|
+
: this.controllerClass);
|
|
140
70
|
return taonProjectsController;
|
|
141
|
-
//#endregion
|
|
142
|
-
}
|
|
143
|
-
//#endregion
|
|
144
|
-
//#region public methods / start if needs to be started
|
|
145
|
-
async startDetachedIfNeedsToBeStarted(options) {
|
|
146
|
-
//#region @backendFunc
|
|
147
|
-
if (this.processLocalInfoObj.isEmpty) {
|
|
148
|
-
// not started ever yet
|
|
149
|
-
await this.startDetached(options);
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
const serviceIsHealthy = await this.isServiceHealthy({
|
|
153
|
-
healthCheckRequestTrys: 1, // just quick check
|
|
154
|
-
});
|
|
155
|
-
if (!serviceIsHealthy) {
|
|
156
|
-
await this.startDetached(options);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
index_1.Helpers.log(`Service "${this.serviceID}" is already started/healthy...`);
|
|
160
|
-
//#endregion
|
|
161
71
|
}
|
|
162
72
|
//#endregion
|
|
163
73
|
//#region public methods / kill
|
|
@@ -167,19 +77,31 @@ class BaseCliWorker {
|
|
|
167
77
|
async kill(options) {
|
|
168
78
|
//#region @backendFunc
|
|
169
79
|
options = options || {};
|
|
170
|
-
|
|
80
|
+
options.methodOptions = base_cli_worker_models_1.BaseCliMethodOptions.from(options.methodOptions);
|
|
81
|
+
if (this.dependencyWorkers.size > 0) {
|
|
82
|
+
for (const [serviceId, worker] of this.dependencyWorkers) {
|
|
83
|
+
index_1.Helpers.info(`Killing dependency worker "${serviceId}"...`);
|
|
84
|
+
await worker.kill({
|
|
85
|
+
methodOptions: options.methodOptions,
|
|
86
|
+
dontRemoveConfigFile: options.dontRemoveConfigFile,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
index_1.Helpers.info(`Killing service "${this.serviceID}"...`);
|
|
171
91
|
if (this.processLocalInfoObj.isEmpty) {
|
|
172
92
|
index_1.Helpers.log(`Service "${this.serviceID}" not started - nothing to kill...`);
|
|
173
93
|
return;
|
|
174
94
|
}
|
|
175
|
-
const ctrl = await this.
|
|
176
|
-
|
|
95
|
+
const ctrl = await this.getRemoteControllerFor({
|
|
96
|
+
methodOptions: options.methodOptions.clone(opt => {
|
|
97
|
+
opt.calledFrom = `${opt.calledFrom}.kill`;
|
|
98
|
+
return opt;
|
|
99
|
+
}),
|
|
177
100
|
});
|
|
178
101
|
try {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
await ctrl.baseCLiWorkerCommand_kill().request();
|
|
102
|
+
await ctrl
|
|
103
|
+
.baseCLiWorkerCommand_kill(options.dontRemoveConfigFile)
|
|
104
|
+
.request();
|
|
183
105
|
index_1.Helpers.log(`Service "${this.serviceID}" killed...`);
|
|
184
106
|
}
|
|
185
107
|
catch (error) {
|
|
@@ -196,16 +118,23 @@ class BaseCliWorker {
|
|
|
196
118
|
*/
|
|
197
119
|
async restart(options) {
|
|
198
120
|
options = options || {};
|
|
199
|
-
options.
|
|
200
|
-
await this.kill(
|
|
121
|
+
options.methodOptions = base_cli_worker_models_1.BaseCliMethodOptions.from(options.methodOptions);
|
|
122
|
+
await this.kill({
|
|
123
|
+
methodOptions: options.methodOptions,
|
|
124
|
+
});
|
|
201
125
|
//longer because os is disposing process previous process
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
126
|
+
index_1.Helpers.info(`Restarting service "${this.serviceID}" ` +
|
|
127
|
+
`in ${options.methodOptions.cliParams.mode} mode...`);
|
|
128
|
+
if (options.methodOptions.cliParams.mode ===
|
|
129
|
+
base_cli_worker_models_1.BaseCLiWorkerStartMode.IN_CURRENT_PROCESS) {
|
|
130
|
+
await this.startNormallyInCurrentProcess({
|
|
131
|
+
methodOptions: options.methodOptions,
|
|
132
|
+
});
|
|
205
133
|
}
|
|
206
134
|
else {
|
|
207
|
-
|
|
208
|
-
|
|
135
|
+
await this.startDetached({
|
|
136
|
+
methodOptions: options.methodOptions,
|
|
137
|
+
});
|
|
209
138
|
}
|
|
210
139
|
}
|
|
211
140
|
//#endregion
|
|
@@ -214,50 +143,212 @@ class BaseCliWorker {
|
|
|
214
143
|
* only for cli start
|
|
215
144
|
* @param cliParams on from cli
|
|
216
145
|
*/
|
|
217
|
-
async cliStartProcedure(
|
|
218
|
-
const detached = !!cliParams['detached'] || !!cliParams['detach'];
|
|
146
|
+
async cliStartProcedure(options) {
|
|
219
147
|
//#region @backendFunc
|
|
220
|
-
|
|
148
|
+
options = options || {};
|
|
149
|
+
const methodOptions = base_cli_worker_models_1.BaseCliMethodOptions.from(options.methodOptions);
|
|
150
|
+
if (methodOptions.cliParams.restart) {
|
|
221
151
|
index_1.Helpers.logInfo(`--- RESTARTING ----`);
|
|
222
152
|
await this.restart({
|
|
223
|
-
|
|
153
|
+
methodOptions,
|
|
224
154
|
});
|
|
225
155
|
process.exit(0);
|
|
226
156
|
}
|
|
227
|
-
if (cliParams
|
|
228
|
-
await this.kill(
|
|
157
|
+
if (methodOptions.cliParams.kill) {
|
|
158
|
+
await this.kill({
|
|
159
|
+
methodOptions,
|
|
160
|
+
});
|
|
229
161
|
process.exit(0);
|
|
230
162
|
}
|
|
231
|
-
if (
|
|
232
|
-
|
|
233
|
-
|
|
163
|
+
if (options.methodOptions.cliParams.mode ===
|
|
164
|
+
base_cli_worker_models_1.BaseCLiWorkerStartMode.IN_CURRENT_PROCESS) {
|
|
165
|
+
await this.startNormallyInCurrentProcess({
|
|
166
|
+
methodOptions,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
await this.startDetachedIfNeedsToBeStarted({
|
|
171
|
+
methodOptions,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const controller = await this.getRemoteControllerFor({
|
|
175
|
+
methodOptions: methodOptions.clone(opt => {
|
|
176
|
+
opt.calledFrom = `${opt.calledFrom}.cliStartProcedure`;
|
|
177
|
+
return opt;
|
|
178
|
+
}),
|
|
179
|
+
});
|
|
180
|
+
return { controller, worker: this, serviceId: this.serviceID };
|
|
181
|
+
//#endregion
|
|
182
|
+
}
|
|
183
|
+
//#endregion
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region protected
|
|
186
|
+
//#region protected methods / get remote context
|
|
187
|
+
async getRemoteContextFor(options) {
|
|
188
|
+
options = options || {};
|
|
189
|
+
options.methodOptions = base_cli_worker_models_1.BaseCliMethodOptions.from(options.methodOptions);
|
|
190
|
+
const ipAddressOfTaonInstance = options.methodOptions.connectionOptions.ipAddressOfTaonInstance ||
|
|
191
|
+
lib_2.CoreModels.localhostDomain;
|
|
192
|
+
// on localhost read data from processLocalInfoObj json
|
|
193
|
+
let port = options.methodOptions.connectionOptions.port ||
|
|
194
|
+
this.processLocalInfoObj.port;
|
|
195
|
+
if (ipAddressOfTaonInstance === lib_2.CoreModels.localhostDomain && !port) {
|
|
196
|
+
if (this.workerIsStarting) {
|
|
197
|
+
try {
|
|
198
|
+
await this.waitForProcessPortSavedToDisk({
|
|
199
|
+
methodOptions: options.methodOptions.clone(opt => {
|
|
200
|
+
opt.calledFrom = `${opt.calledFrom}.getRemoteContextFor.localhost`;
|
|
201
|
+
return opt;
|
|
202
|
+
}),
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
console.error(`[getRemoteContextFor] Error while waiting for process port saved to disk`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (this.processLocalInfoPortNotInited) {
|
|
210
|
+
throw new Error(`Can't connect to remote context on localhost - port is not defined.
|
|
211
|
+
This can happen when the worker process is not started yet.
|
|
212
|
+
`);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
port = this.processLocalInfoObj.port;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
// this.workerRemoteContextFor[ipAddressOfTaonInstance] = remoteCtx;
|
|
219
|
+
const useHttps = ipAddressOfTaonInstance !== lib_2.CoreModels.localhostDomain &&
|
|
220
|
+
ipAddressOfTaonInstance !== lib_2.CoreModels.localhostIp127;
|
|
221
|
+
const protocol = useHttps ? 'https' : 'http';
|
|
222
|
+
const overrideRemoteHost = `${protocol}://${ipAddressOfTaonInstance}${port ? `:${port}` : ''}`;
|
|
223
|
+
const remoteCtx = this.workerContextTemplate().cloneAsRemote({
|
|
224
|
+
overrideRemoteHost,
|
|
225
|
+
});
|
|
226
|
+
// @LAST chache remote context per ipAddressOfTaonInstance
|
|
227
|
+
const remoteEndpoitnContext = await remoteCtx.initialize();
|
|
228
|
+
return remoteEndpoitnContext;
|
|
229
|
+
}
|
|
230
|
+
//#endregion
|
|
231
|
+
//#region protected fields & getters / path to process local info
|
|
232
|
+
get pathToProcessLocalInfoJson() {
|
|
233
|
+
//#region @backendFunc
|
|
234
|
+
// console.log('os.userInfo()', os.userInfo());
|
|
235
|
+
return base_cli_worker_utils_1.BaseCliWorkerUtils.getPathToProcessLocalInfoJson(this.serviceID);
|
|
236
|
+
//#endregion
|
|
237
|
+
}
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region protected fields & getters / should wait for process port saved to disk
|
|
240
|
+
get processLocalInfoPortNotInited() {
|
|
241
|
+
return (!this.processLocalInfoObj.port ||
|
|
242
|
+
isNaN(Number(this.processLocalInfoObj.port)));
|
|
243
|
+
}
|
|
244
|
+
//#endregion
|
|
245
|
+
//#region protected fields & getters / worker is starting
|
|
246
|
+
get workerIsStarting() {
|
|
247
|
+
return !!this.processLocalInfoObj.startTimestamp;
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region protected methods / start if needs to be started
|
|
251
|
+
async startDetachedIfNeedsToBeStarted(options) {
|
|
252
|
+
//#region @backendFunc
|
|
253
|
+
options = options || {};
|
|
254
|
+
options.methodOptions = base_cli_worker_models_1.BaseCliMethodOptions.from(options.methodOptions);
|
|
255
|
+
if (this.processLocalInfoObj.isEmpty) {
|
|
256
|
+
// not started ever yet
|
|
257
|
+
await this.startDetached({
|
|
258
|
+
methodOptions: options.methodOptions,
|
|
259
|
+
});
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const serviceIsHealthy = await this.isServiceHealthy({
|
|
263
|
+
healthCheckRequestTrys: 1, // just quick check
|
|
264
|
+
methodOptions: options.methodOptions,
|
|
265
|
+
});
|
|
266
|
+
if (!serviceIsHealthy) {
|
|
267
|
+
await this.startDetached({
|
|
268
|
+
methodOptions: options.methodOptions,
|
|
269
|
+
});
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
index_1.Helpers.log(`Service "${this.serviceID}" is already started/healthy...`);
|
|
273
|
+
//#endregion
|
|
274
|
+
}
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region protected methods / start normally in current process
|
|
277
|
+
/**
|
|
278
|
+
* <strong>IMPORTANT USE ONLY IN DEVELOPMENT !!!</strong>
|
|
279
|
+
* for production use startDetachedIfNeedsToBeStarted()
|
|
280
|
+
* start normally process
|
|
281
|
+
* this will crash if process already started
|
|
282
|
+
*/
|
|
283
|
+
async startNormallyInCurrentProcess(options) {
|
|
284
|
+
//#region @backendFunc
|
|
285
|
+
options = options || {};
|
|
286
|
+
options.methodOptions = base_cli_worker_models_1.BaseCliMethodOptions.from(options.methodOptions);
|
|
287
|
+
index_1.Helpers.taskStarted(`[${this.serviceID}] Process start in current process...`);
|
|
288
|
+
await this.killWorkerWithLowerVersion({
|
|
289
|
+
methodOptions: options.methodOptions,
|
|
290
|
+
});
|
|
291
|
+
await this.preventStartIfAlreadyStarted({
|
|
292
|
+
methodOptions: options.methodOptions,
|
|
293
|
+
});
|
|
294
|
+
const port = await this.getServicePort();
|
|
295
|
+
this.saveProcessInfo({
|
|
296
|
+
port,
|
|
297
|
+
serviceID: this.serviceID,
|
|
298
|
+
pid: process.pid,
|
|
299
|
+
startTimestamp: Date.now(),
|
|
300
|
+
version: this.serviceVersion,
|
|
301
|
+
});
|
|
302
|
+
const workerMainContext = this.workerContextTemplate().cloneAsNormal({
|
|
303
|
+
overrideHost: `http://localhost:${port}`,
|
|
304
|
+
});
|
|
305
|
+
await workerMainContext.initialize();
|
|
306
|
+
await this.initializeWorkerMetadata({
|
|
307
|
+
methodOptions: options.methodOptions,
|
|
308
|
+
});
|
|
309
|
+
index_1.Helpers.info(`Service started !`);
|
|
310
|
+
this.preventExternalConfigChange();
|
|
311
|
+
if (lib_2._.isFunction(options.actionBeforeTerminalUI)) {
|
|
312
|
+
await options.actionBeforeTerminalUI();
|
|
313
|
+
}
|
|
314
|
+
if (this.terminalUI) {
|
|
315
|
+
this.terminalUI.displaySpecialWorkerReadyMessage();
|
|
316
|
+
await this.terminalUI.infoScreen();
|
|
234
317
|
}
|
|
235
318
|
else {
|
|
236
|
-
|
|
319
|
+
console.log(`
|
|
320
|
+
[${lib_1.config.frameworkName}-helpers] No terminal UI configured. Not displaying anything.
|
|
321
|
+
`);
|
|
237
322
|
}
|
|
238
323
|
//#endregion
|
|
239
324
|
}
|
|
240
325
|
//#endregion
|
|
241
|
-
//#region prevent external config change
|
|
326
|
+
//#region protected methods / prevent external config change
|
|
242
327
|
preventExternalConfigChange() {
|
|
243
328
|
//#region @backendFunc
|
|
244
329
|
index_1.Helpers.info(`watching: ${this.pathToProcessLocalInfoJson}`);
|
|
245
330
|
const currentConfig = this.processLocalInfoObj;
|
|
246
|
-
|
|
331
|
+
lib_2.chokidar.watch(this.pathToProcessLocalInfoJson).on('change', () => {
|
|
247
332
|
index_1.Helpers.log(`Service data changed...`);
|
|
248
333
|
if (!this.processLocalInfoObj.isEquals(currentConfig)) {
|
|
249
|
-
|
|
334
|
+
lib_2.UtilsTerminal.clearConsole();
|
|
250
335
|
index_1.Helpers.error(`Service config data externally changed... killing service`, false, true);
|
|
251
336
|
}
|
|
252
337
|
});
|
|
253
338
|
//#endregion
|
|
254
339
|
}
|
|
255
340
|
//#endregion
|
|
256
|
-
//#region prevent prevent start if already started
|
|
257
|
-
async preventStartIfAlreadyStarted() {
|
|
341
|
+
//#region protected methods / prevent prevent start if already started
|
|
342
|
+
async preventStartIfAlreadyStarted(options) {
|
|
258
343
|
//#region @backendFunc
|
|
344
|
+
options = options || {};
|
|
345
|
+
options.methodOptions = base_cli_worker_models_1.BaseCliMethodOptions.from(options.methodOptions);
|
|
346
|
+
if (!this.processLocalInfoObj.pid || this.processLocalInfoPortNotInited) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
259
349
|
try {
|
|
260
350
|
const isHealthy = await this.isServiceHealthy({
|
|
351
|
+
methodOptions: options.methodOptions,
|
|
261
352
|
healthCheckRequestTrys: 2, // check only twice
|
|
262
353
|
});
|
|
263
354
|
if (isHealthy) {
|
|
@@ -268,18 +359,27 @@ class BaseCliWorker {
|
|
|
268
359
|
//#endregion
|
|
269
360
|
}
|
|
270
361
|
//#endregion
|
|
271
|
-
//#region prevent kill worker with lower version
|
|
272
|
-
async killWorkerWithLowerVersion() {
|
|
362
|
+
//#region protected methods / prevent kill worker with lower version
|
|
363
|
+
async killWorkerWithLowerVersion(options) {
|
|
273
364
|
//#region @backendFunc
|
|
365
|
+
options = options || {};
|
|
366
|
+
options.methodOptions = base_cli_worker_models_1.BaseCliMethodOptions.from(options.methodOptions);
|
|
367
|
+
if (!this.processLocalInfoObj.pid) {
|
|
368
|
+
index_1.Helpers.logInfo(`No pid found - skipping version check...`);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
274
371
|
index_1.Helpers.taskStarted(`[${this.serviceID}] Checking if current working version is up to date...`);
|
|
275
372
|
try {
|
|
276
|
-
const ctrl = await this.
|
|
277
|
-
|
|
373
|
+
const ctrl = await this.getRemoteControllerFor({
|
|
374
|
+
methodOptions: options.methodOptions.clone(opt => {
|
|
375
|
+
opt.calledFrom = `${opt.calledFrom}.killWorkerWithLowerVersion`;
|
|
376
|
+
return opt;
|
|
377
|
+
}),
|
|
278
378
|
});
|
|
279
379
|
index_1.Helpers.logInfo(`[${this.serviceID}] Checking if current working version is up to date...`);
|
|
280
380
|
// console.log('this.processLocalInfoObj', this.processLocalInfoObj);
|
|
281
381
|
const req = await ctrl
|
|
282
|
-
.baseCLiWorkerCommand_hasUpToDateVersion(
|
|
382
|
+
.baseCLiWorkerCommand_hasUpToDateVersion(lib_2._.merge(this.processLocalInfoObj, {
|
|
283
383
|
version: this.serviceVersion,
|
|
284
384
|
}))
|
|
285
385
|
.request();
|
|
@@ -289,16 +389,19 @@ class BaseCliWorker {
|
|
|
289
389
|
index_1.Helpers.info(`[${this.serviceID}] Killing service with lower version...`);
|
|
290
390
|
await this.kill({
|
|
291
391
|
dontRemoveConfigFile: true,
|
|
392
|
+
methodOptions: options.methodOptions,
|
|
292
393
|
});
|
|
293
|
-
await
|
|
394
|
+
await lib_2.UtilsTerminal.wait(1);
|
|
294
395
|
}
|
|
295
396
|
}
|
|
296
|
-
catch (error) {
|
|
397
|
+
catch (error) {
|
|
398
|
+
index_1.Helpers.logInfo(`Probably no need to kill worker with lower version`);
|
|
399
|
+
}
|
|
297
400
|
index_1.Helpers.taskDone(`[${this.serviceID}] Current working version is up to date !`);
|
|
298
401
|
//#endregion
|
|
299
402
|
}
|
|
300
403
|
//#endregion
|
|
301
|
-
//#region is service healthy
|
|
404
|
+
//#region protected methods / is service healthy
|
|
302
405
|
/**
|
|
303
406
|
* This has 2 purposes:
|
|
304
407
|
* - infinite check when when detached process finished starting
|
|
@@ -307,13 +410,15 @@ class BaseCliWorker {
|
|
|
307
410
|
async isServiceHealthy(options) {
|
|
308
411
|
//#region @backendFunc
|
|
309
412
|
options = options || {};
|
|
413
|
+
options.methodOptions = base_cli_worker_models_1.BaseCliMethodOptions.from(options.methodOptions);
|
|
310
414
|
const healthCheckRequestTrys = options.healthCheckRequestTrys || 1;
|
|
415
|
+
//#region timestamp checking
|
|
311
416
|
let i = 0; // 15 seconds to start worker
|
|
312
417
|
while (true) {
|
|
313
418
|
i++;
|
|
314
|
-
index_1.Helpers.logInfo(`[${this.serviceID}][timestamp-checking]
|
|
315
|
-
|
|
316
|
-
if (!workerIsStarting) {
|
|
419
|
+
index_1.Helpers.logInfo(`[${this.serviceID}][timestamp-checking][${options.methodOptions.calledFrom}]
|
|
420
|
+
Checking if service "${this.serviceID}" is starting...`);
|
|
421
|
+
if (!this.workerIsStarting) {
|
|
317
422
|
// initialized worker does not have startTimestamp
|
|
318
423
|
break;
|
|
319
424
|
}
|
|
@@ -327,15 +432,15 @@ class BaseCliWorker {
|
|
|
327
432
|
return false;
|
|
328
433
|
}
|
|
329
434
|
index_1.Helpers.log('[timestamp-checking] Waiting 500 miliseonds for service to start...');
|
|
330
|
-
await
|
|
435
|
+
await lib_2.UtilsTerminal.wait(1);
|
|
331
436
|
}
|
|
437
|
+
//#endregion
|
|
332
438
|
i = 0;
|
|
333
|
-
const isWaitingNotCheckingWhen =
|
|
439
|
+
const isWaitingNotCheckingWhen = 20;
|
|
334
440
|
while (true) {
|
|
335
441
|
i++;
|
|
336
442
|
try {
|
|
337
|
-
|
|
338
|
-
// TODO: check why this is may not work
|
|
443
|
+
//#region initial message
|
|
339
444
|
if (isWaitingNotCheckingWhen === i) {
|
|
340
445
|
index_1.Helpers.info(`[${this.serviceID}] Waiting for service "${this.serviceID}" ` +
|
|
341
446
|
`to start...`);
|
|
@@ -344,14 +449,21 @@ class BaseCliWorker {
|
|
|
344
449
|
index_1.Helpers.log(`[${this.serviceID}] Checking if service "${this.serviceID}" ` +
|
|
345
450
|
`is healthy...`);
|
|
346
451
|
}
|
|
347
|
-
|
|
348
|
-
|
|
452
|
+
//#endregion
|
|
453
|
+
//#region request check
|
|
454
|
+
const ctrl = await this.getRemoteControllerFor({
|
|
455
|
+
methodOptions: options.methodOptions.clone(opt => {
|
|
456
|
+
opt.calledFrom = `${opt.calledFrom}.isServiceHealthy`;
|
|
457
|
+
return opt;
|
|
458
|
+
}),
|
|
349
459
|
});
|
|
350
460
|
index_1.Helpers.log(`Sending is healthy request...`);
|
|
351
461
|
// console.log('this.processLocalInfoObj', this.processLocalInfoObj);
|
|
352
462
|
const req = await ctrl
|
|
353
463
|
.baseCLiWorkerCommand_isHealthy(this.processLocalInfoObj)
|
|
354
|
-
.request(
|
|
464
|
+
.request({
|
|
465
|
+
// timeout: 1000,
|
|
466
|
+
});
|
|
355
467
|
const isHealthy = req.body.booleanValue;
|
|
356
468
|
// console.log('isHealthy', { isHealthy });
|
|
357
469
|
if (isHealthy) {
|
|
@@ -360,16 +472,13 @@ class BaseCliWorker {
|
|
|
360
472
|
else {
|
|
361
473
|
index_1.Helpers.log(`Service "${this.serviceID}" is not healthy (response is false)...`);
|
|
362
474
|
}
|
|
475
|
+
//#endregion
|
|
363
476
|
if (isHealthy || i === healthCheckRequestTrys) {
|
|
364
477
|
return isHealthy;
|
|
365
478
|
}
|
|
366
|
-
else {
|
|
367
|
-
index_1.Helpers.log('Trying again...');
|
|
368
|
-
await lib_1.UtilsTerminal.wait(1);
|
|
369
|
-
continue;
|
|
370
|
-
}
|
|
371
479
|
}
|
|
372
480
|
catch (error) {
|
|
481
|
+
//#region error handling
|
|
373
482
|
if (i >= isWaitingNotCheckingWhen && error?.message) {
|
|
374
483
|
console.error(error.message);
|
|
375
484
|
}
|
|
@@ -377,26 +486,28 @@ class BaseCliWorker {
|
|
|
377
486
|
if (i === healthCheckRequestTrys) {
|
|
378
487
|
return false;
|
|
379
488
|
}
|
|
380
|
-
|
|
381
|
-
index_1.Helpers.log('Trying again...');
|
|
382
|
-
await lib_1.UtilsTerminal.wait(1);
|
|
383
|
-
continue;
|
|
384
|
-
}
|
|
489
|
+
//#endregion
|
|
385
490
|
}
|
|
491
|
+
index_1.Helpers.log('Trying again...');
|
|
492
|
+
await lib_2.UtilsTerminal.wait(1);
|
|
386
493
|
}
|
|
387
494
|
//#endregion
|
|
388
495
|
}
|
|
389
496
|
//#endregion
|
|
390
|
-
//#region start detached
|
|
497
|
+
//#region protected methods / start detached
|
|
391
498
|
/**
|
|
392
499
|
* start if not started detached process
|
|
393
500
|
*/
|
|
394
501
|
async startDetached(options) {
|
|
395
502
|
//#region @backendFunc
|
|
396
503
|
options = options || {};
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
504
|
+
options.methodOptions = base_cli_worker_models_1.BaseCliMethodOptions.from(options.methodOptions);
|
|
505
|
+
if (options.methodOptions.cliParams.mode ===
|
|
506
|
+
base_cli_worker_models_1.BaseCLiWorkerStartMode.CHILD_PROCESS) {
|
|
507
|
+
index_1.Helpers.logInfo(`[${this.serviceID}][startDetached] ` +
|
|
508
|
+
` Starting in current terminal
|
|
509
|
+
"${lib_2.chalk.bold(this.startCommand)}"...`);
|
|
510
|
+
await lib_2.UtilsProcess.startAsyncChildProcessCommandUntil(this.startCommand, {
|
|
400
511
|
untilOptions: {
|
|
401
512
|
stdout: [this.SPECIAL_WORKER_READY_MESSAGE],
|
|
402
513
|
stderr: [this.SPECIAL_WORKER_READY_MESSAGE],
|
|
@@ -405,29 +516,31 @@ class BaseCliWorker {
|
|
|
405
516
|
});
|
|
406
517
|
}
|
|
407
518
|
else {
|
|
408
|
-
index_1.Helpers.logInfo(`[${this.serviceID}][startDetached]
|
|
409
|
-
|
|
519
|
+
index_1.Helpers.logInfo(`[${this.serviceID}][startDetached] ` +
|
|
520
|
+
`Starting in new terminal
|
|
521
|
+
"${lib_2.chalk.bold(this.startCommand)}"...`);
|
|
522
|
+
await lib_2.UtilsProcess.startInNewTerminalWindow(this.startCommand);
|
|
410
523
|
}
|
|
411
|
-
index_1.Helpers.logInfo(`"${
|
|
524
|
+
index_1.Helpers.logInfo(`"${lib_2.chalk.bold(this.serviceID)}" - waiting until healthy (Infinite health check trys )...`);
|
|
412
525
|
const isServiceHealthy = await this.isServiceHealthy({
|
|
526
|
+
methodOptions: options.methodOptions,
|
|
413
527
|
healthCheckRequestTrys: Infinity, // wait infinity until started
|
|
414
528
|
});
|
|
415
529
|
if (!isServiceHealthy) {
|
|
416
|
-
|
|
417
|
-
return;
|
|
530
|
+
throw `Not able to start service "${this.serviceID}"...`;
|
|
418
531
|
}
|
|
419
|
-
index_1.Helpers.logInfo(`Healthy service "${
|
|
532
|
+
index_1.Helpers.logInfo(`Healthy service "${lib_2.chalk.bold(this.serviceID)}" started.`);
|
|
420
533
|
//#endregion
|
|
421
534
|
}
|
|
422
535
|
//#endregion
|
|
423
|
-
//#region save process info
|
|
536
|
+
//#region protected methods / save process info
|
|
424
537
|
saveProcessInfo(processConfig) {
|
|
425
538
|
//#region @backendFunc
|
|
426
539
|
processConfig = processConfig || {};
|
|
427
540
|
if (index_1.Helpers.exists(this.pathToProcessLocalInfoJson)) {
|
|
428
541
|
const jsonConfig = index_1.Helpers.readJson(this.pathToProcessLocalInfoJson);
|
|
429
|
-
if (
|
|
430
|
-
processConfig =
|
|
542
|
+
if (lib_2._.isObject(jsonConfig) && Object.keys(jsonConfig).length > 0) {
|
|
543
|
+
processConfig = lib_2._.merge(jsonConfig, processConfig);
|
|
431
544
|
}
|
|
432
545
|
}
|
|
433
546
|
index_1.Helpers.log(`Saving process info to "${this.pathToProcessLocalInfoJson}"...`);
|
|
@@ -436,13 +549,18 @@ class BaseCliWorker {
|
|
|
436
549
|
//#endregion
|
|
437
550
|
}
|
|
438
551
|
//#endregion
|
|
439
|
-
//#region initialize worker
|
|
440
|
-
async initializeWorkerMetadata() {
|
|
552
|
+
//#region protected methods / initialize worker
|
|
553
|
+
async initializeWorkerMetadata(options) {
|
|
441
554
|
//#region @backendFunc
|
|
555
|
+
options = options || {};
|
|
556
|
+
options.methodOptions = base_cli_worker_models_1.BaseCliMethodOptions.from(options.methodOptions);
|
|
442
557
|
while (true) {
|
|
443
558
|
try {
|
|
444
|
-
const portControllerInstance = await this.
|
|
445
|
-
|
|
559
|
+
const portControllerInstance = await this.getRemoteControllerFor({
|
|
560
|
+
methodOptions: options.methodOptions.clone(opt => {
|
|
561
|
+
opt.calledFrom = `${opt.calledFrom}.initializeWorkerMetadata`;
|
|
562
|
+
return opt;
|
|
563
|
+
}),
|
|
446
564
|
});
|
|
447
565
|
await portControllerInstance
|
|
448
566
|
.baseCLiWorkerCommand_initializeMetadata(this.serviceID, this.serviceVersion)
|
|
@@ -458,7 +576,7 @@ class BaseCliWorker {
|
|
|
458
576
|
startTimestamp: null,
|
|
459
577
|
});
|
|
460
578
|
index_1.Helpers.info(`[${this.serviceID}][${this.serviceVersion}] Retrying to initialize worker metadata...`);
|
|
461
|
-
await
|
|
579
|
+
await lib_2.UtilsTerminal.wait(1);
|
|
462
580
|
}
|
|
463
581
|
}
|
|
464
582
|
// process.on('SIGINT', () => {
|
|
@@ -467,51 +585,46 @@ class BaseCliWorker {
|
|
|
467
585
|
//#endregion
|
|
468
586
|
}
|
|
469
587
|
//#endregion
|
|
470
|
-
//#region wait for process port saved to disk
|
|
588
|
+
//#region protected methods / wait for process port saved to disk
|
|
471
589
|
async waitForProcessPortSavedToDisk(options) {
|
|
472
590
|
//#region @backendFunc
|
|
473
591
|
options = options || {};
|
|
474
|
-
|
|
592
|
+
options.methodOptions = base_cli_worker_models_1.BaseCliMethodOptions.from(options.methodOptions);
|
|
593
|
+
index_1.Helpers.logInfo(`[${this.serviceID}][${[options.methodOptions.calledFrom]}]` +
|
|
475
594
|
` Waiting for process port saved to disk...`);
|
|
476
595
|
index_1.Helpers.log(`in ${this.pathToProcessLocalInfoJson}`);
|
|
477
|
-
|
|
478
|
-
const MAX_TRYS = 10;
|
|
596
|
+
const MAX_TRYS = 30;
|
|
479
597
|
let i = 0;
|
|
480
|
-
if (
|
|
481
|
-
while (
|
|
598
|
+
if (this.processLocalInfoPortNotInited) {
|
|
599
|
+
while (this.processLocalInfoPortNotInited) {
|
|
482
600
|
i++;
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
break;
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
index_1.Helpers.logInfo(`[${this.serviceID}][${this.serviceVersion}] waiting/checking again for port...`);
|
|
601
|
+
if (this.processLocalInfoPortNotInited) {
|
|
602
|
+
index_1.Helpers.logInfo(`[${this.serviceID}][${this.serviceVersion}][${options.methodOptions.calledFrom}]
|
|
603
|
+
waiting/checking again for port...`);
|
|
490
604
|
if (i > MAX_TRYS) {
|
|
491
|
-
|
|
492
|
-
|
|
605
|
+
throw `[${this.serviceID}][${this.serviceVersion}][${options.methodOptions.calledFrom}]
|
|
606
|
+
Can't get port for remote connection..
|
|
607
|
+
worker process did not start correctly`;
|
|
493
608
|
}
|
|
494
|
-
await
|
|
609
|
+
await lib_2.UtilsTerminal.wait(1);
|
|
610
|
+
}
|
|
611
|
+
else {
|
|
612
|
+
index_1.Helpers.taskDone(`[${this.serviceID}][${this.serviceVersion}][${options.methodOptions.calledFrom}]
|
|
613
|
+
port assigned: ${this.processLocalInfoObj.port}`);
|
|
614
|
+
break;
|
|
495
615
|
}
|
|
496
616
|
}
|
|
497
617
|
}
|
|
498
618
|
//#endregion
|
|
499
619
|
}
|
|
500
620
|
//#endregion
|
|
501
|
-
//#region get free port
|
|
621
|
+
//#region protected methods / get free port
|
|
502
622
|
async getServicePort() {
|
|
503
623
|
//#region @backendFunc
|
|
504
624
|
index_1.Helpers.logInfo(`Getting free port for service...`);
|
|
505
|
-
const port = await
|
|
625
|
+
const port = await lib_2.Utils.getFreePort({
|
|
506
626
|
startFrom: START_PORT_FOR_SERVICES,
|
|
507
627
|
});
|
|
508
|
-
this.saveProcessInfo({
|
|
509
|
-
port,
|
|
510
|
-
serviceID: this.serviceID,
|
|
511
|
-
pid: process.pid,
|
|
512
|
-
startTimestamp: Date.now(),
|
|
513
|
-
version: this.serviceVersion,
|
|
514
|
-
});
|
|
515
628
|
index_1.Helpers.logInfo(`Done getting free port for service...`);
|
|
516
629
|
return port;
|
|
517
630
|
//#endregion
|