@platformatic/runtime 1.36.0 → 1.36.1
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/fixtures/do-not-restart-on-crash/platformatic.runtime.json +14 -0
- package/fixtures/do-not-restart-on-crash/services/a/platformatic.service.json +14 -0
- package/fixtures/do-not-restart-on-crash/services/a/plugin.js +9 -0
- package/fixtures/restart-on-crash/platformatic.runtime.json +1 -1
- package/lib/api-client.js +1 -1
- package/lib/errors.js +0 -1
- package/lib/generator/runtime-generator.js +1 -1
- package/lib/schema.js +7 -0
- package/lib/start.js +18 -31
- package/lib/versions/v1.36.0.js +11 -0
- package/package.json +10 -10
package/lib/api-client.js
CHANGED
package/lib/errors.js
CHANGED
|
@@ -25,7 +25,6 @@ module.exports = {
|
|
|
25
25
|
FailedToUnlinkManagementApiSocket: createError(`${ERROR_PREFIX}_FAILED_TO_UNLINK_MANAGEMENT_API_SOCKET`, 'Failed to unlink management API socket "%s"'),
|
|
26
26
|
LogFileNotFound: createError(`${ERROR_PREFIX}_LOG_FILE_NOT_FOUND`, 'Log file with index %s not found', 404),
|
|
27
27
|
CannotFindGeneratorForTemplateError: createError(`${ERROR_PREFIX}_CANNOT_FIND_GENERATOR_FOR_TEMPLATE`, 'Cannot find a generator for template "%s"'),
|
|
28
|
-
WorkerExitCodeError: createError(`${ERROR_PREFIX}_WORKER_EXIT_CODE`, 'The worker exited with non-zero exit code "%s"'),
|
|
29
28
|
WorkerIsRequired: createError(`${ERROR_PREFIX}_REQUIRED_WORKER`, 'The worker parameter is required'),
|
|
30
29
|
|
|
31
30
|
// TODO: should remove next one as it's not used anymore
|
|
@@ -90,7 +90,7 @@ class RuntimeGenerator extends BaseGenerator {
|
|
|
90
90
|
this.addServicesDependencies()
|
|
91
91
|
|
|
92
92
|
this.addEnvVars({
|
|
93
|
-
PLT_SERVER_HOSTNAME: '
|
|
93
|
+
PLT_SERVER_HOSTNAME: '127.0.0.1',
|
|
94
94
|
PORT: this.config.port || 3042,
|
|
95
95
|
PLT_SERVER_LOGGER_LEVEL: this.config.logLevel || 'info',
|
|
96
96
|
PLT_MANAGEMENT_API: true
|
package/lib/schema.js
CHANGED
package/lib/start.js
CHANGED
|
@@ -4,7 +4,6 @@ const { once } = require('node:events')
|
|
|
4
4
|
const inspector = require('node:inspector')
|
|
5
5
|
const { join, resolve, dirname } = require('node:path')
|
|
6
6
|
const { writeFile } = require('node:fs/promises')
|
|
7
|
-
const { setTimeout: sleep } = require('node:timers/promises')
|
|
8
7
|
const { pathToFileURL } = require('node:url')
|
|
9
8
|
const { Worker } = require('node:worker_threads')
|
|
10
9
|
const { start: serviceStart } = require('@platformatic/service')
|
|
@@ -13,7 +12,6 @@ const closeWithGrace = require('close-with-grace')
|
|
|
13
12
|
const { loadConfig } = require('./load-config')
|
|
14
13
|
const { startManagementApi } = require('./management-api')
|
|
15
14
|
const { startPrometheusServer } = require('./prom-server.js')
|
|
16
|
-
const { WorkerExitCodeError } = require('./errors')
|
|
17
15
|
const { parseInspectorOptions, wrapConfigInRuntimeConfig } = require('./config')
|
|
18
16
|
const { RuntimeApiClient, getRuntimeLogsDir } = require('./api-client.js')
|
|
19
17
|
const errors = require('./errors')
|
|
@@ -64,19 +62,6 @@ async function buildRuntime (configManager, env = process.env) {
|
|
|
64
62
|
|
|
65
63
|
let managementApi = null
|
|
66
64
|
|
|
67
|
-
let exiting = false
|
|
68
|
-
closeWithGrace((event, cb) => {
|
|
69
|
-
exiting = true
|
|
70
|
-
worker.postMessage(event)
|
|
71
|
-
worker.once('exit', (code) => {
|
|
72
|
-
if (code !== 0) {
|
|
73
|
-
cb(new WorkerExitCodeError(code))
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
cb()
|
|
77
|
-
})
|
|
78
|
-
})
|
|
79
|
-
|
|
80
65
|
if (config.hotReload) {
|
|
81
66
|
/* c8 ignore next 3 */
|
|
82
67
|
process.on('SIGUSR2', () => {
|
|
@@ -93,7 +78,7 @@ async function buildRuntime (configManager, env = process.env) {
|
|
|
93
78
|
worker.on('exit', (code) => {
|
|
94
79
|
// runtimeApiClient.started can be false if a stop command was issued
|
|
95
80
|
// via the management API.
|
|
96
|
-
if (
|
|
81
|
+
if (config.restartOnError === false || !runtimeApiClient.started) {
|
|
97
82
|
// We must stop those here in case the `closeWithGrace` callback
|
|
98
83
|
// was not called.
|
|
99
84
|
configManager.fileWatcher?.stopWatching()
|
|
@@ -103,8 +88,12 @@ async function buildRuntime (configManager, env = process.env) {
|
|
|
103
88
|
|
|
104
89
|
worker = startWorker({ config, dirname, runtimeLogsDir }, env)
|
|
105
90
|
setupExit()
|
|
106
|
-
|
|
107
|
-
|
|
91
|
+
|
|
92
|
+
once(worker, 'message').then((msg) => {
|
|
93
|
+
runtimeApiClient.setWorker(worker).catch(() => {
|
|
94
|
+
// TODO: currently we restart if the worker fails to start intermitently
|
|
95
|
+
// should we limit this to a number of retries?
|
|
96
|
+
})
|
|
108
97
|
})
|
|
109
98
|
})
|
|
110
99
|
}
|
|
@@ -162,7 +151,16 @@ async function startCommand (args) {
|
|
|
162
151
|
runtime = await buildRuntime(wrappedConfig)
|
|
163
152
|
}
|
|
164
153
|
|
|
165
|
-
|
|
154
|
+
const res = await runtime.start()
|
|
155
|
+
|
|
156
|
+
closeWithGrace(async (event) => {
|
|
157
|
+
if (event.err instanceof Error) {
|
|
158
|
+
console.error(event.err)
|
|
159
|
+
}
|
|
160
|
+
await runtime.close()
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
return res
|
|
166
164
|
} catch (err) {
|
|
167
165
|
if (err.code === 'PLT_CONFIG_NO_CONFIG_FILE_FOUND' && args.length === 1) {
|
|
168
166
|
const config = {
|
|
@@ -188,12 +186,6 @@ async function startCommand (args) {
|
|
|
188
186
|
return startCommand(['--config', toWrite])
|
|
189
187
|
}
|
|
190
188
|
|
|
191
|
-
if (err.code === 'PLT_RUNTIME_RUNTIME_EXIT') {
|
|
192
|
-
console.log('Runtime exited before startup was completed, restarting')
|
|
193
|
-
await sleep(1000)
|
|
194
|
-
return startCommand(args)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
189
|
if (err.filenames) {
|
|
198
190
|
console.error(`Missing config file!
|
|
199
191
|
Be sure to have a config file with one of the following names:
|
|
@@ -207,12 +199,7 @@ async function startCommand (args) {
|
|
|
207
199
|
process.exit(1)
|
|
208
200
|
}
|
|
209
201
|
|
|
210
|
-
|
|
211
|
-
console.error(err?.message)
|
|
212
|
-
|
|
213
|
-
if (err?.cause) {
|
|
214
|
-
console.error(`${err.cause}`)
|
|
215
|
-
}
|
|
202
|
+
console.error(err)
|
|
216
203
|
|
|
217
204
|
process.exit(1)
|
|
218
205
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/runtime",
|
|
3
|
-
"version": "1.36.
|
|
3
|
+
"version": "1.36.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"typescript": "^5.4.2",
|
|
35
35
|
"undici-oidc-interceptor": "^0.5.0",
|
|
36
36
|
"why-is-node-running": "^2.2.2",
|
|
37
|
-
"@platformatic/sql-graphql": "1.36.
|
|
38
|
-
"@platformatic/sql-mapper": "1.36.
|
|
37
|
+
"@platformatic/sql-graphql": "1.36.1",
|
|
38
|
+
"@platformatic/sql-mapper": "1.36.1"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@fastify/error": "^3.4.1",
|
|
@@ -63,13 +63,13 @@
|
|
|
63
63
|
"undici": "^6.9.0",
|
|
64
64
|
"why-is-node-running": "^2.2.2",
|
|
65
65
|
"ws": "^8.16.0",
|
|
66
|
-
"@platformatic/
|
|
67
|
-
"@platformatic/config": "1.36.
|
|
68
|
-
"@platformatic/
|
|
69
|
-
"@platformatic/
|
|
70
|
-
"@platformatic/
|
|
71
|
-
"@platformatic/telemetry": "1.36.
|
|
72
|
-
"@platformatic/utils": "1.36.
|
|
66
|
+
"@platformatic/composer": "1.36.1",
|
|
67
|
+
"@platformatic/config": "1.36.1",
|
|
68
|
+
"@platformatic/db": "1.36.1",
|
|
69
|
+
"@platformatic/generators": "1.36.1",
|
|
70
|
+
"@platformatic/service": "1.36.1",
|
|
71
|
+
"@platformatic/telemetry": "1.36.1",
|
|
72
|
+
"@platformatic/utils": "1.36.1"
|
|
73
73
|
},
|
|
74
74
|
"standard": {
|
|
75
75
|
"ignore": [
|