@dxos/phoenix 0.8.4-main.dedc0f3 → 0.8.4-main.e00bdcdb52
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/bin/watchdog.mjs +5 -0
- package/dist/lib/node-esm/index.mjs +10 -57
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/phoenix.d.ts +2 -2
- package/dist/types/src/phoenix.d.ts.map +1 -1
- package/dist/types/src/testing-utils.d.ts.map +1 -1
- package/dist/types/src/utils.d.ts.map +1 -1
- package/dist/types/src/watchdog.d.ts +3 -3
- package/dist/types/src/watchdog.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -8
- package/src/phoenix.node.test.ts +1 -4
- package/src/phoenix.ts +2 -3
- package/src/watchdog.node.test.ts +2 -3
- package/src/watchdog.ts +3 -3
package/bin/watchdog.mjs
CHANGED
|
@@ -33,7 +33,6 @@ var waitForPidFileBeingFilledWithInfo = async (pidFile) => waitForCondition({
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
// src/phoenix.ts
|
|
36
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/common/phoenix/src/phoenix.ts";
|
|
37
36
|
var scriptDir = typeof __dirname === "string" ? __dirname : dirname(new URL(import.meta.url).pathname);
|
|
38
37
|
var Phoenix = class _Phoenix {
|
|
39
38
|
/**
|
|
@@ -75,22 +74,12 @@ var Phoenix = class _Phoenix {
|
|
|
75
74
|
log.error("Monitor died unexpectedly", {
|
|
76
75
|
code,
|
|
77
76
|
signal
|
|
78
|
-
}, {
|
|
79
|
-
F: __dxlog_file,
|
|
80
|
-
L: 54,
|
|
81
|
-
S: this,
|
|
82
|
-
C: (f, a) => f(...a)
|
|
83
77
|
});
|
|
84
78
|
}
|
|
85
79
|
});
|
|
86
80
|
watchDog.on("error", (err) => {
|
|
87
81
|
log.error("Monitor error", {
|
|
88
82
|
err
|
|
89
|
-
}, {
|
|
90
|
-
F: __dxlog_file,
|
|
91
|
-
L: 59,
|
|
92
|
-
S: this,
|
|
93
|
-
C: (f, a) => f(...a)
|
|
94
83
|
});
|
|
95
84
|
});
|
|
96
85
|
await waitForPidFileBeingFilledWithInfo(params.pidFile);
|
|
@@ -116,15 +105,7 @@ var Phoenix = class _Phoenix {
|
|
|
116
105
|
try {
|
|
117
106
|
process.kill(pid, signal);
|
|
118
107
|
} catch (err) {
|
|
119
|
-
invariant(err instanceof Error, "Invalid error type"
|
|
120
|
-
F: __dxlog_file,
|
|
121
|
-
L: 87,
|
|
122
|
-
S: this,
|
|
123
|
-
A: [
|
|
124
|
-
"err instanceof Error",
|
|
125
|
-
"'Invalid error type'"
|
|
126
|
-
]
|
|
127
|
-
});
|
|
108
|
+
invariant(err instanceof Error, "Invalid error type");
|
|
128
109
|
if (err.message.includes("ESRCH") || err.name.includes("ESRCH")) {
|
|
129
110
|
unlinkSync(pidFile);
|
|
130
111
|
} else {
|
|
@@ -145,27 +126,20 @@ import { existsSync as existsSync3, unlinkSync as unlinkSync2, writeFileSync as
|
|
|
145
126
|
import { synchronized } from "@dxos/async";
|
|
146
127
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
147
128
|
import { log as log2 } from "@dxos/log";
|
|
148
|
-
function _define_property(obj, key, value) {
|
|
149
|
-
if (key in obj) {
|
|
150
|
-
Object.defineProperty(obj, key, {
|
|
151
|
-
value,
|
|
152
|
-
enumerable: true,
|
|
153
|
-
configurable: true,
|
|
154
|
-
writable: true
|
|
155
|
-
});
|
|
156
|
-
} else {
|
|
157
|
-
obj[key] = value;
|
|
158
|
-
}
|
|
159
|
-
return obj;
|
|
160
|
-
}
|
|
161
129
|
function _ts_decorate(decorators, target, key, desc) {
|
|
162
130
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
163
131
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
164
132
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
165
133
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
166
134
|
}
|
|
167
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/common/phoenix/src/watchdog.ts";
|
|
168
135
|
var WatchDog = class {
|
|
136
|
+
_params;
|
|
137
|
+
_lock;
|
|
138
|
+
_child;
|
|
139
|
+
_restarts = 0;
|
|
140
|
+
constructor(_params) {
|
|
141
|
+
this._params = _params;
|
|
142
|
+
}
|
|
169
143
|
async start() {
|
|
170
144
|
const { cwd, shell, env, command, args } = {
|
|
171
145
|
cwd: process.cwd(),
|
|
@@ -223,26 +197,13 @@ var WatchDog = class {
|
|
|
223
197
|
if (this._params.maxRestarts !== void 0 && this._restarts >= this._params.maxRestarts) {
|
|
224
198
|
this._err("Max restarts number is reached");
|
|
225
199
|
} else {
|
|
226
|
-
log2("Restarting..."
|
|
227
|
-
F: __dxlog_file2,
|
|
228
|
-
L: 120,
|
|
229
|
-
S: this,
|
|
230
|
-
C: (f, a) => f(...a)
|
|
231
|
-
});
|
|
200
|
+
log2("Restarting...");
|
|
232
201
|
this._restarts++;
|
|
233
202
|
await this.start();
|
|
234
203
|
}
|
|
235
204
|
}
|
|
236
205
|
async _killWithSignal(signal) {
|
|
237
|
-
invariant2(this._child?.pid, "Child process has no pid."
|
|
238
|
-
F: __dxlog_file2,
|
|
239
|
-
L: 127,
|
|
240
|
-
S: this,
|
|
241
|
-
A: [
|
|
242
|
-
"this._child?.pid",
|
|
243
|
-
"'Child process has no pid.'"
|
|
244
|
-
]
|
|
245
|
-
});
|
|
206
|
+
invariant2(this._child?.pid, "Child process has no pid.");
|
|
246
207
|
this._child.kill(signal);
|
|
247
208
|
this._child = void 0;
|
|
248
209
|
}
|
|
@@ -259,14 +220,6 @@ var WatchDog = class {
|
|
|
259
220
|
encoding: "utf-8"
|
|
260
221
|
});
|
|
261
222
|
}
|
|
262
|
-
constructor(_params) {
|
|
263
|
-
_define_property(this, "_params", void 0);
|
|
264
|
-
_define_property(this, "_lock", void 0);
|
|
265
|
-
_define_property(this, "_child", void 0);
|
|
266
|
-
_define_property(this, "_restarts", void 0);
|
|
267
|
-
this._params = _params;
|
|
268
|
-
this._restarts = 0;
|
|
269
|
-
}
|
|
270
223
|
};
|
|
271
224
|
_ts_decorate([
|
|
272
225
|
synchronized
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/phoenix.ts", "../../../src/utils.ts", "../../../src/defs.ts", "../../../src/watchdog.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { fork } from 'node:child_process';\nimport { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\
|
|
5
|
-
"mappings": ";;;AAIA,SAASA,YAAY;AACrB,SAASC,cAAAA,aAAYC,WAAWC,gBAAAA,eAAcC,YAAYC,qBAAqB;AAC/E,SAASC,SAASC,YAAY;
|
|
6
|
-
"names": ["fork", "existsSync", "mkdirSync", "readFileSync", "unlinkSync", "writeFileSync", "dirname", "join", "pkgUp", "invariant", "log", "existsSync", "readFileSync", "waitForCondition", "WATCHDOG_START_TIMEOUT", "WATCHDOG_STOP_TIMEOUT", "WATCHDOG_CHECK_INTERVAL", "waitForPidDeletion", "pidFile", "waitForCondition", "condition", "existsSync", "timeout", "WATCHDOG_STOP_TIMEOUT", "interval", "WATCHDOG_CHECK_INTERVAL", "waitForPidFileBeingFilledWithInfo", "readFileSync", "encoding", "includes", "WATCHDOG_START_TIMEOUT", "error", "Error", "scriptDir", "__dirname", "dirname", "URL", "url", "pathname", "Phoenix", "start", "params", "existsSync", "pidFile", "stop", "waitForPidDeletion", "logFile", "errFile", "forEach", "filename", "mkdirSync", "recursive", "writeFileSync", "encoding", "watchdogPath", "join", "pkgUp", "sync", "cwd", "watchDog", "fork", "JSON", "stringify", "detached", "on", "code", "signal", "log", "error", "err", "waitForPidFileBeingFilledWithInfo", "disconnect", "unref", "info", "force", "Error", "fileContent", "readFileSync", "includes", "pid", "parse", "process", "kill", "invariant", "message", "name", "unlinkSync", "spawn", "existsSync", "unlinkSync", "writeFileSync", "synchronized", "invariant", "log", "WatchDog", "start", "cwd", "shell", "env", "command", "args", "process", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { fork } from 'node:child_process';\nimport { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport pkgUp from 'pkg-up';\n\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { waitForPidDeletion, waitForPidFileBeingFilledWithInfo } from './utils';\nimport { type ProcessInfo, type WatchDogProps } from './watchdog';\n\nconst scriptDir = typeof __dirname === 'string' ? __dirname : dirname(new URL(import.meta.url).pathname);\n\n/**\n * Utils to start/stop detached process with errors and logs handling.\n */\nexport class Phoenix {\n /**\n * Starts detached watchdog process which starts and monitors selected command.\n */\n static async start(params: WatchDogProps): Promise<ProcessInfo> {\n {\n // Clear stale pid file.\n if (existsSync(params.pidFile)) {\n await Phoenix.stop(params.pidFile);\n }\n\n await waitForPidDeletion(params.pidFile);\n }\n\n {\n // Create log folders.\n [params.logFile, params.errFile, params.pidFile].forEach((filename) => {\n if (!existsSync(filename)) {\n mkdirSync(dirname(filename), { recursive: true });\n writeFileSync(filename, '', { encoding: 'utf-8' });\n }\n });\n }\n\n const watchdogPath = join(dirname(pkgUp.sync({ cwd: scriptDir })!), 'bin', 'watchdog.mjs');\n\n const watchDog = fork(watchdogPath, [JSON.stringify(params)], {\n detached: true,\n });\n\n watchDog.on('exit', (code, signal) => {\n if (code && code !== 0) {\n log.error('Monitor died unexpectedly', { code, signal });\n }\n });\n\n watchDog.on('error', (err) => {\n log.error('Monitor error', { err });\n });\n\n await waitForPidFileBeingFilledWithInfo(params.pidFile);\n\n watchDog.disconnect();\n watchDog.unref();\n\n return Phoenix.info(params.pidFile);\n }\n\n /**\n * Stops detached watchdog process by PID info written down in PID file.\n */\n static async stop(pidFile: string, force = false): Promise<void> {\n if (!existsSync(pidFile)) {\n throw new Error('PID file does not exist');\n }\n const fileContent = readFileSync(pidFile, { encoding: 'utf-8' });\n if (!fileContent.includes('pid')) {\n throw new Error('Invalid PID file content');\n }\n\n const { pid } = JSON.parse(fileContent);\n const signal: NodeJS.Signals = force ? 'SIGKILL' : 'SIGINT';\n try {\n process.kill(pid, signal);\n } catch (err) {\n invariant(err instanceof Error, 'Invalid error type');\n if (err.message.includes('ESRCH') || err.name.includes('ESRCH')) {\n // Process is already dead.\n unlinkSync(pidFile);\n } else {\n throw err;\n }\n }\n }\n\n static info(pidFile: string): ProcessInfo {\n return JSON.parse(readFileSync(pidFile, { encoding: 'utf-8' }));\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { existsSync, readFileSync } from 'node:fs';\n\nimport { waitForCondition } from '@dxos/async';\n\nimport { WATCHDOG_CHECK_INTERVAL, WATCHDOG_START_TIMEOUT, WATCHDOG_STOP_TIMEOUT } from './defs';\n\nexport const waitForPidCreation = async (pidFile: string) =>\n waitForCondition({\n condition: () => existsSync(pidFile),\n timeout: WATCHDOG_START_TIMEOUT,\n interval: WATCHDOG_CHECK_INTERVAL,\n });\n\nexport const waitForPidDeletion = async (pidFile: string) =>\n waitForCondition({\n condition: () => !existsSync(pidFile),\n timeout: WATCHDOG_STOP_TIMEOUT,\n interval: WATCHDOG_CHECK_INTERVAL,\n });\n\nexport const waitForPidFileBeingFilledWithInfo = async (pidFile: string) =>\n waitForCondition({\n condition: () => readFileSync(pidFile, { encoding: 'utf-8' }).includes('pid'),\n timeout: WATCHDOG_START_TIMEOUT,\n interval: WATCHDOG_CHECK_INTERVAL,\n error: new Error('Lock file is not being propagated with info.'),\n });\n", "//\n// Copyright 2023 DXOS.org\n//\n\nexport const LOCK_TIMEOUT = 1_000;\nexport const LOCK_CHECK_INTERVAL = 50;\nexport const WATCHDOG_START_TIMEOUT = 10_000;\nexport const WATCHDOG_STOP_TIMEOUT = 1_000;\nexport const WATCHDOG_CHECK_INTERVAL = 50;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type ChildProcessWithoutNullStreams, spawn } from 'node:child_process';\nimport { existsSync, unlinkSync, writeFileSync } from 'node:fs';\nimport { type FileHandle } from 'node:fs/promises';\n\nimport { synchronized } from '@dxos/async';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nimport { waitForPidDeletion, waitForPidFileBeingFilledWithInfo } from './utils';\n\nexport type ProcessInfo = WatchDogProps & {\n pid?: number;\n started?: number;\n restarts?: number;\n running?: boolean;\n};\n\nexport type WatchDogProps = {\n profile?: string; // Human readable process identifier\n pidFile: string; // Path to PID file\n\n //\n // Log files and associated logging options for this instance\n //\n logFile: string; // Path to log output all logs\n errFile: string; // Path to log output from child stderr\n\n //\n // Basic configuration options\n //\n maxRestarts?: number | undefined; // Sets the maximum number of times a given script should run\n killTree?: boolean | undefined; // Kills the entire child process tree on `exit`\n\n //\n // Command to spawn as well as options and other vars\n // (env, cwd, etc) to pass along\n //\n command: string; // Binary to run (default: 'node')\n args?: string[] | undefined; // Additional arguments to pass to the script,\n\n //\n // More specific options to pass along to `child_process.spawn` which\n // will override anything passed to the `spawnWith` option\n //\n env?: NodeJS.ProcessEnv | undefined;\n cwd?: string | undefined;\n shell?: boolean | undefined;\n};\n\nexport class WatchDog {\n private _lock?: FileHandle; // TODO(burdon): Not used?\n private _child?: ChildProcessWithoutNullStreams;\n private _restarts = 0;\n\n constructor(private readonly _params: WatchDogProps) {}\n\n @synchronized\n async start(): Promise<void> {\n const { cwd, shell, env, command, args } = { cwd: process.cwd(), ...this._params };\n\n this._log(`Spawning process \\`\\`\\`${command} ${args?.join(' ')}\\`\\`\\``);\n this._child = spawn(command, args, { cwd, shell, env, stdio: 'pipe' });\n\n this._child.stdout.on('data', (data: Uint8Array) => {\n this._log(String(data));\n });\n this._child.stderr.on('data', (data: Uint8Array) => {\n this._err(data);\n });\n this._child.on('close', async (code: number, signal: number | NodeJS.Signals) => {\n if (code && code !== 0 && signal !== 'SIGINT' && signal !== 'SIGKILL') {\n this._err(`Died unexpectedly with exit code ${code} (signal: ${signal}).`);\n await this.restart();\n }\n this._log(`Stopped with exit code ${code} (signal: ${signal}).`);\n if (existsSync(this._params.pidFile)) {\n unlinkSync(this._params.pidFile);\n }\n });\n\n const childInfo: ProcessInfo = {\n pid: this._child.pid,\n started: Date.now(),\n restarts: this._restarts,\n ...this._params,\n };\n\n writeFileSync(this._params.pidFile, JSON.stringify(childInfo, undefined, 2), { encoding: 'utf-8' });\n\n await waitForPidFileBeingFilledWithInfo(this._params.pidFile);\n }\n\n /**\n * Sends SIGKILL to the child process and the tree it spawned (if `killTree` param is `true`).\n */\n @synchronized\n async kill(): Promise<void> {\n if (!this._child) {\n return;\n }\n\n await this._killWithSignal('SIGKILL');\n\n if (existsSync(this._params.pidFile)) {\n unlinkSync(this._params.pidFile);\n }\n\n await waitForPidDeletion(this._params.pidFile);\n }\n\n async restart(): Promise<void> {\n await this.kill();\n if (this._params.maxRestarts !== undefined && this._restarts >= this._params.maxRestarts) {\n this._err('Max restarts number is reached');\n } else {\n log('Restarting...');\n this._restarts++;\n await this.start();\n }\n }\n\n async _killWithSignal(signal: number | NodeJS.Signals): Promise<void> {\n invariant(this._child?.pid, 'Child process has no pid.');\n this._child.kill(signal);\n this._child = undefined;\n }\n\n private _log(message: string | Uint8Array): void {\n writeFileSync(this._params.logFile, message + '\\n', {\n flag: 'a+',\n encoding: 'utf-8',\n });\n }\n\n private _err(message: string | Uint8Array): void {\n this._log(message);\n writeFileSync(this._params.errFile, message + '\\n', {\n flag: 'a+',\n encoding: 'utf-8',\n });\n }\n}\n"],
|
|
5
|
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FileSync", "dirname", "join", "pkgUp", "invariant", "log", "existsSync", "readFileSync", "waitForCondition", "WATCHDOG_START_TIMEOUT", "WATCHDOG_STOP_TIMEOUT", "WATCHDOG_CHECK_INTERVAL", "waitForPidDeletion", "pidFile", "waitForCondition", "condition", "existsSync", "timeout", "WATCHDOG_STOP_TIMEOUT", "interval", "WATCHDOG_CHECK_INTERVAL", "waitForPidFileBeingFilledWithInfo", "readFileSync", "encoding", "includes", "WATCHDOG_START_TIMEOUT", "error", "Error", "scriptDir", "__dirname", "dirname", "URL", "url", "pathname", "Phoenix", "start", "params", "existsSync", "pidFile", "stop", "waitForPidDeletion", "logFile", "errFile", "forEach", "filename", "mkdirSync", "recursive", "writeFileSync", "encoding", "watchdogPath", "join", "pkgUp", "sync", "cwd", "watchDog", "fork", "JSON", "stringify", "detached", "on", "code", "signal", "log", "error", "err", "waitForPidFileBeingFilledWithInfo", "disconnect", "unref", "info", "force", "Error", "fileContent", "readFileSync", "includes", "pid", "parse", "process", "kill", "invariant", "message", "name", "unlinkSync", "spawn", "existsSync", "unlinkSync", "writeFileSync", "synchronized", "invariant", "log", "WatchDog", "_lock", "_child", "_restarts", "_params", "start", "cwd", "shell", "env", "command", "args", "process", "_log", "join", "spawn", "stdio", "stdout", "on", "data", "String", "stderr", "_err", "code", "signal", "restart", "existsSync", "pidFile", "unlinkSync", "childInfo", "pid", "started", "Date", "now", "restarts", "writeFileSync", "JSON", "stringify", "undefined", "encoding", "waitForPidFileBeingFilledWithInfo", "kill", "_killWithSignal", "waitForPidDeletion", "maxRestarts", "log", "invariant", "message", "logFile", "flag", "errFile"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/defs.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/defs.ts":{"bytes":1115,"imports":[],"format":"esm"},"src/utils.ts":{"bytes":3586,"imports":[{"path":"node:fs","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"src/defs.ts","kind":"import-statement","original":"./defs"}],"format":"esm"},"src/phoenix.ts":{"bytes":10765,"imports":[{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"src/utils.ts","kind":"import-statement","original":"./utils"}],"format":"esm"},"src/watchdog.ts":{"bytes":13964,"imports":[{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"src/utils.ts","kind":"import-statement","original":"./utils"}],"format":"esm"},"src/index.ts":{"bytes":900,"imports":[{"path":"src/phoenix.ts","kind":"import-statement","original":"./phoenix"},{"path":"src/watchdog.ts","kind":"import-statement","original":"./watchdog"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":14855},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"pkg-up","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["Phoenix","WatchDog"],"entryPoint":"src/index.ts","inputs":{"src/phoenix.ts":{"bytesInOutput":2613},"src/utils.ts":{"bytesInOutput":586},"src/defs.ts":{"bytesInOutput":101},"src/index.ts":{"bytesInOutput":0},"src/watchdog.ts":{"bytesInOutput":3410}},"bytes":6979}}}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ProcessInfo, type
|
|
1
|
+
import { type ProcessInfo, type WatchDogProps } from './watchdog';
|
|
2
2
|
/**
|
|
3
3
|
* Utils to start/stop detached process with errors and logs handling.
|
|
4
4
|
*/
|
|
@@ -6,7 +6,7 @@ export declare class Phoenix {
|
|
|
6
6
|
/**
|
|
7
7
|
* Starts detached watchdog process which starts and monitors selected command.
|
|
8
8
|
*/
|
|
9
|
-
static start(params:
|
|
9
|
+
static start(params: WatchDogProps): Promise<ProcessInfo>;
|
|
10
10
|
/**
|
|
11
11
|
* Stops detached watchdog process by PID info written down in PID file.
|
|
12
12
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phoenix.d.ts","sourceRoot":"","sources":["../../../src/phoenix.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"phoenix.d.ts","sourceRoot":"","sources":["../../../src/phoenix.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAIlE;;GAEG;AACH,qBAAa,OAAO;IAClB;;OAEG;IACH,OAAa,KAAK,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,CAAC,CA0C9D;IAED;;OAEG;IACH,OAAa,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAsB/D;IAED,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAExC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testing-utils.d.ts","sourceRoot":"","sources":["../../../src/testing-utils.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,QAAQ,8BAA8B,CAAC;AAMpD,eAAO,MAAM,kBAAkB,YAI9B,CAAC;AAEF,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"testing-utils.d.ts","sourceRoot":"","sources":["../../../src/testing-utils.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,QAAQ,8BAA8B,CAAC;AAMpD,eAAO,MAAM,kBAAkB,YAI9B,CAAC;AAEF,eAAO,MAAM,UAAU,iBAAkB,MAAM,EAAE,SAMhD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,kBAAkB,YAAmB,MAAM,qBAKpD,CAAC;AAEL,eAAO,MAAM,kBAAkB,YAAmB,MAAM,qBAKpD,CAAC;AAEL,eAAO,MAAM,iCAAiC,YAAmB,MAAM,qBAMnE,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export type ProcessInfo =
|
|
1
|
+
export type ProcessInfo = WatchDogProps & {
|
|
2
2
|
pid?: number;
|
|
3
3
|
started?: number;
|
|
4
4
|
restarts?: number;
|
|
5
5
|
running?: boolean;
|
|
6
6
|
};
|
|
7
|
-
export type
|
|
7
|
+
export type WatchDogProps = {
|
|
8
8
|
profile?: string;
|
|
9
9
|
pidFile: string;
|
|
10
10
|
logFile: string;
|
|
@@ -22,7 +22,7 @@ export declare class WatchDog {
|
|
|
22
22
|
private _lock?;
|
|
23
23
|
private _child?;
|
|
24
24
|
private _restarts;
|
|
25
|
-
constructor(_params:
|
|
25
|
+
constructor(_params: WatchDogProps);
|
|
26
26
|
start(): Promise<void>;
|
|
27
27
|
/**
|
|
28
28
|
* Sends SIGKILL to the child process and the tree it spawned (if `killTree` param is `true`).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watchdog.d.ts","sourceRoot":"","sources":["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