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