@platformatic/control
Advanced tools
+42
-5
@@ -1,2 +0,2 @@ | ||
| import { safeRemove } from '@platformatic/foundation' | ||
| import { createDebugLogger, ensureLoggableError, safeRemove } from '@platformatic/foundation' | ||
| import { exec, spawn } from 'node:child_process' | ||
@@ -96,6 +96,17 @@ import { access, readdir } from 'node:fs/promises' | ||
| #webSockets = new Set() | ||
| #socketPath | ||
| #logger | ||
| #debugLogger | ||
| constructor (options = {}) { | ||
| this.#socketPath = options?.socket | ||
| this.#logger = options?.logger | ||
| this.#debugLogger = createDebugLogger('runtime:api') | ||
| } | ||
| async getMatchingRuntime (opts = {}) { | ||
| const runtimes = await this.getRuntimes() | ||
| this.#debugLogger('Found runtimes', runtimes) | ||
| let runtime = null | ||
@@ -116,8 +127,10 @@ if (opts.pid) { | ||
| async getRuntimes () { | ||
| if (this.#socketPath) { | ||
| return [await this.getRuntimeMetadata(0)] | ||
| } | ||
| const runtimePIDs = platform() === 'win32' ? await this.#getWindowsRuntimePIDs() : await this.#getUnixRuntimePIDs() | ||
| const getMetadataRequests = await Promise.allSettled( | ||
| runtimePIDs.map(async runtimePID => { | ||
| return this.getRuntimeMetadata(runtimePID) | ||
| }) | ||
| runtimePIDs.map(runtimePID => this.getRuntimeMetadata(runtimePID)) | ||
| ) | ||
@@ -130,4 +143,14 @@ | ||
| this.#debugLogger(`Runtime ${runtimePID} get metadata result`, metadataRequest) | ||
| if (metadataRequest.status === 'rejected') { | ||
| await this.#removeRuntimeTmpDir(runtimePID).catch(() => {}) | ||
| // If it is just a non running runtime, we can remove its tmp dir, otherwise we log the error | ||
| if (metadataRequest.reason.code !== 'ECONNREFUSED') { | ||
| this.#logger?.warn( | ||
| { error: ensureLoggableError(metadataRequest.reason) }, | ||
| `Failed to retrieve metadata for runtime with PID ${runtimePID}.` | ||
| ) | ||
| } else { | ||
| await this.#removeRuntimeTmpDir(runtimePID).catch(() => {}) | ||
| } | ||
| } else { | ||
@@ -610,2 +633,6 @@ runtimes.push(metadataRequest.value) | ||
| #getSocketPathFromPid (pid) { | ||
| if (this.#socketPath) { | ||
| return this.#socketPath | ||
| } | ||
| if (platform() === 'win32') { | ||
@@ -618,2 +645,4 @@ return PLATFORMATIC_PIPE_PREFIX + pid | ||
| async #getUnixRuntimePIDs () { | ||
| this.#debugLogger('Getting runtime PIDs from folder', PLATFORMATIC_TMP_DIR) | ||
| try { | ||
@@ -628,2 +657,4 @@ await access(PLATFORMATIC_TMP_DIR) | ||
| this.#debugLogger('Candidate runtime paths', runtimeDirs) | ||
| for (const runtimeDir of runtimeDirs) { | ||
@@ -635,2 +666,5 @@ // Only consider directory that can be a PID | ||
| } | ||
| this.#debugLogger('Runtime PIDS', runtimePIDs) | ||
| return runtimePIDs | ||
@@ -642,2 +676,5 @@ } | ||
| const runtimePIDs = [] | ||
| this.#debugLogger('Available named pipes', pipeNames) | ||
| for (const pipeName of pipeNames) { | ||
@@ -644,0 +681,0 @@ if (pipeName.startsWith(PLATFORMATIC_PIPE_PREFIX)) { |
+4
-4
| { | ||
| "name": "@platformatic/control", | ||
| "version": "3.35.1", | ||
| "version": "3.36.0", | ||
| "description": "Platformatic Control", | ||
@@ -26,4 +26,4 @@ "main": "lib/index.js", | ||
| "typescript": "^5.5.4", | ||
| "@platformatic/runtime": "3.35.1", | ||
| "@platformatic/service": "3.35.1" | ||
| "@platformatic/runtime": "3.36.0", | ||
| "@platformatic/service": "3.36.0" | ||
| }, | ||
@@ -38,3 +38,3 @@ "dependencies": { | ||
| "ws": "^8.16.0", | ||
| "@platformatic/foundation": "3.35.1" | ||
| "@platformatic/foundation": "3.36.0" | ||
| }, | ||
@@ -41,0 +41,0 @@ "engines": { |
40898
2.86%792
3.39%+ Added
+ Added
+ Added
- Removed