@platformatic/control 3.35.1 → 3.36.0
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/lib/index.js +42 -5
- package/package.json +4 -4
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { safeRemove } from '@platformatic/foundation'
|
|
1
|
+
import { createDebugLogger, ensureLoggableError, safeRemove } from '@platformatic/foundation'
|
|
2
2
|
import { exec, spawn } from 'node:child_process'
|
|
3
3
|
import { access, readdir } from 'node:fs/promises'
|
|
4
4
|
import { EOL, platform, tmpdir } from 'node:os'
|
|
@@ -93,10 +93,21 @@ export async function getMatchingRuntime (client, positionals) {
|
|
|
93
93
|
export class RuntimeApiClient {
|
|
94
94
|
#undiciClients = new Map()
|
|
95
95
|
#webSockets = new Set()
|
|
96
|
+
#socketPath
|
|
97
|
+
#logger
|
|
98
|
+
#debugLogger
|
|
99
|
+
|
|
100
|
+
constructor (options = {}) {
|
|
101
|
+
this.#socketPath = options?.socket
|
|
102
|
+
this.#logger = options?.logger
|
|
103
|
+
this.#debugLogger = createDebugLogger('runtime:api')
|
|
104
|
+
}
|
|
96
105
|
|
|
97
106
|
async getMatchingRuntime (opts = {}) {
|
|
98
107
|
const runtimes = await this.getRuntimes()
|
|
99
108
|
|
|
109
|
+
this.#debugLogger('Found runtimes', runtimes)
|
|
110
|
+
|
|
100
111
|
let runtime = null
|
|
101
112
|
if (opts.pid) {
|
|
102
113
|
runtime = runtimes.find(runtime => runtime.pid === parseInt(opts.pid))
|
|
@@ -112,12 +123,14 @@ export class RuntimeApiClient {
|
|
|
112
123
|
}
|
|
113
124
|
|
|
114
125
|
async getRuntimes () {
|
|
126
|
+
if (this.#socketPath) {
|
|
127
|
+
return [await this.getRuntimeMetadata(0)]
|
|
128
|
+
}
|
|
129
|
+
|
|
115
130
|
const runtimePIDs = platform() === 'win32' ? await this.#getWindowsRuntimePIDs() : await this.#getUnixRuntimePIDs()
|
|
116
131
|
|
|
117
132
|
const getMetadataRequests = await Promise.allSettled(
|
|
118
|
-
runtimePIDs.map(
|
|
119
|
-
return this.getRuntimeMetadata(runtimePID)
|
|
120
|
-
})
|
|
133
|
+
runtimePIDs.map(runtimePID => this.getRuntimeMetadata(runtimePID))
|
|
121
134
|
)
|
|
122
135
|
|
|
123
136
|
const runtimes = []
|
|
@@ -125,8 +138,18 @@ export class RuntimeApiClient {
|
|
|
125
138
|
const runtimePID = runtimePIDs[i]
|
|
126
139
|
const metadataRequest = getMetadataRequests[i]
|
|
127
140
|
|
|
141
|
+
this.#debugLogger(`Runtime ${runtimePID} get metadata result`, metadataRequest)
|
|
142
|
+
|
|
128
143
|
if (metadataRequest.status === 'rejected') {
|
|
129
|
-
|
|
144
|
+
// If it is just a non running runtime, we can remove its tmp dir, otherwise we log the error
|
|
145
|
+
if (metadataRequest.reason.code !== 'ECONNREFUSED') {
|
|
146
|
+
this.#logger?.warn(
|
|
147
|
+
{ error: ensureLoggableError(metadataRequest.reason) },
|
|
148
|
+
`Failed to retrieve metadata for runtime with PID ${runtimePID}.`
|
|
149
|
+
)
|
|
150
|
+
} else {
|
|
151
|
+
await this.#removeRuntimeTmpDir(runtimePID).catch(() => {})
|
|
152
|
+
}
|
|
130
153
|
} else {
|
|
131
154
|
runtimes.push(metadataRequest.value)
|
|
132
155
|
}
|
|
@@ -604,6 +627,10 @@ export class RuntimeApiClient {
|
|
|
604
627
|
}
|
|
605
628
|
|
|
606
629
|
#getSocketPathFromPid (pid) {
|
|
630
|
+
if (this.#socketPath) {
|
|
631
|
+
return this.#socketPath
|
|
632
|
+
}
|
|
633
|
+
|
|
607
634
|
if (platform() === 'win32') {
|
|
608
635
|
return PLATFORMATIC_PIPE_PREFIX + pid
|
|
609
636
|
}
|
|
@@ -611,6 +638,8 @@ export class RuntimeApiClient {
|
|
|
611
638
|
}
|
|
612
639
|
|
|
613
640
|
async #getUnixRuntimePIDs () {
|
|
641
|
+
this.#debugLogger('Getting runtime PIDs from folder', PLATFORMATIC_TMP_DIR)
|
|
642
|
+
|
|
614
643
|
try {
|
|
615
644
|
await access(PLATFORMATIC_TMP_DIR)
|
|
616
645
|
} catch {
|
|
@@ -620,18 +649,26 @@ export class RuntimeApiClient {
|
|
|
620
649
|
const runtimeDirs = await readdir(PLATFORMATIC_TMP_DIR, { withFileTypes: true })
|
|
621
650
|
const runtimePIDs = []
|
|
622
651
|
|
|
652
|
+
this.#debugLogger('Candidate runtime paths', runtimeDirs)
|
|
653
|
+
|
|
623
654
|
for (const runtimeDir of runtimeDirs) {
|
|
624
655
|
// Only consider directory that can be a PID
|
|
625
656
|
if (runtimeDir.isDirectory() && runtimeDir.name.match(/^\d+$/)) {
|
|
626
657
|
runtimePIDs.push(parseInt(runtimeDir.name))
|
|
627
658
|
}
|
|
628
659
|
}
|
|
660
|
+
|
|
661
|
+
this.#debugLogger('Runtime PIDS', runtimePIDs)
|
|
662
|
+
|
|
629
663
|
return runtimePIDs
|
|
630
664
|
}
|
|
631
665
|
|
|
632
666
|
async #getWindowsRuntimePIDs () {
|
|
633
667
|
const pipeNames = await this.#getWindowsNamedPipes()
|
|
634
668
|
const runtimePIDs = []
|
|
669
|
+
|
|
670
|
+
this.#debugLogger('Available named pipes', pipeNames)
|
|
671
|
+
|
|
635
672
|
for (const pipeName of pipeNames) {
|
|
636
673
|
if (pipeName.startsWith(PLATFORMATIC_PIPE_PREFIX)) {
|
|
637
674
|
const runtimePID = pipeName.replace(PLATFORMATIC_PIPE_PREFIX, '')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/control",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.36.0",
|
|
4
4
|
"description": "Platformatic Control",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"split2": "^4.2.0",
|
|
24
24
|
"tsd": "^0.33.0",
|
|
25
25
|
"typescript": "^5.5.4",
|
|
26
|
-
"@platformatic/runtime": "3.
|
|
27
|
-
"@platformatic/service": "3.
|
|
26
|
+
"@platformatic/runtime": "3.36.0",
|
|
27
|
+
"@platformatic/service": "3.36.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@fastify/error": "^4.0.0",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"table": "^6.8.1",
|
|
35
35
|
"undici": "^7.0.0",
|
|
36
36
|
"ws": "^8.16.0",
|
|
37
|
-
"@platformatic/foundation": "3.
|
|
37
|
+
"@platformatic/foundation": "3.36.0"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=22.19.0"
|