@platformatic/runtime 2.0.0-alpha.8 → 2.0.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/config.d.ts +53 -116
- package/fixtures/configs/{invalid-autoload-with-services.json → invalid-web-with-services.json} +8 -4
- package/fixtures/configs/monorepo-watch.json +2 -4
- package/fixtures/do-not-restart-on-crash/services/a/platformatic.service.json +7 -5
- package/fixtures/management-api/services/service-1/platformatic.json +7 -4
- package/fixtures/restart-on-crash/services/a/platformatic.service.json +7 -5
- package/fixtures/sample-runtime/package.json +2 -2
- package/fixtures/sample-runtime/services/rival/package.json +1 -1
- package/fixtures/sample-runtime-with-2-services/package.json +2 -2
- package/fixtures/sample-runtime-with-2-services/services/foobar/package.json +1 -1
- package/fixtures/sample-runtime-with-2-services/services/rival/package.json +1 -1
- package/index.js +3 -0
- package/lib/config.js +48 -25
- package/lib/errors.js +1 -1
- package/lib/generator/runtime-generator.js +12 -6
- package/lib/logger.js +1 -1
- package/lib/management-api.js +13 -4
- package/lib/runtime.js +25 -10
- package/lib/schema.js +78 -65
- package/lib/start.js +13 -3
- package/lib/upgrade.js +0 -4
- package/lib/utils.js +18 -2
- package/lib/versions/v2.0.0.js +10 -1
- package/lib/worker/app.js +10 -10
- package/lib/worker/default-stackable.js +3 -2
- package/lib/worker/itc.js +16 -3
- package/lib/worker/main.js +10 -4
- package/package.json +21 -22
- package/schema.json +301 -499
package/lib/runtime.js
CHANGED
|
@@ -7,12 +7,8 @@ const inspector = require('node:inspector')
|
|
|
7
7
|
const { join } = require('node:path')
|
|
8
8
|
const { setTimeout: sleep } = require('node:timers/promises')
|
|
9
9
|
const { Worker } = require('node:worker_threads')
|
|
10
|
-
|
|
11
10
|
const { ITC } = require('@platformatic/itc')
|
|
12
|
-
const {
|
|
13
|
-
errors: { ensureLoggableError },
|
|
14
|
-
executeWithTimeout
|
|
15
|
-
} = require('@platformatic/utils')
|
|
11
|
+
const { ensureLoggableError, executeWithTimeout } = require('@platformatic/utils')
|
|
16
12
|
const ts = require('tail-file-stream')
|
|
17
13
|
const { createThreadInterceptor } = require('undici-thread-interceptor')
|
|
18
14
|
|
|
@@ -22,7 +18,7 @@ const { createLogger } = require('./logger')
|
|
|
22
18
|
const { startManagementApi } = require('./management-api')
|
|
23
19
|
const { startPrometheusServer } = require('./prom-server')
|
|
24
20
|
const { getRuntimeTmpDir } = require('./utils')
|
|
25
|
-
const { sendViaITC } = require('./worker/itc')
|
|
21
|
+
const { sendViaITC, waitEventFromITC } = require('./worker/itc')
|
|
26
22
|
const { kId, kITC, kConfig } = require('./worker/symbols')
|
|
27
23
|
|
|
28
24
|
const platformaticVersion = require('../package.json').version
|
|
@@ -151,7 +147,7 @@ class Runtime extends EventEmitter {
|
|
|
151
147
|
this.startCollectingMetrics()
|
|
152
148
|
}
|
|
153
149
|
|
|
154
|
-
this
|
|
150
|
+
this.#showUrl()
|
|
155
151
|
return this.#url
|
|
156
152
|
}
|
|
157
153
|
|
|
@@ -176,7 +172,6 @@ class Runtime extends EventEmitter {
|
|
|
176
172
|
|
|
177
173
|
this.emit('restarted')
|
|
178
174
|
|
|
179
|
-
this.logger.info(`Platformatic is now listening at ${this.#url}`)
|
|
180
175
|
return this.#url
|
|
181
176
|
}
|
|
182
177
|
|
|
@@ -458,6 +453,10 @@ class Runtime extends EventEmitter {
|
|
|
458
453
|
}
|
|
459
454
|
}
|
|
460
455
|
|
|
456
|
+
getRuntimeEnv () {
|
|
457
|
+
return this.#configManager.env
|
|
458
|
+
}
|
|
459
|
+
|
|
461
460
|
getRuntimeConfig () {
|
|
462
461
|
return this.#configManager.current
|
|
463
462
|
}
|
|
@@ -530,6 +529,12 @@ class Runtime extends EventEmitter {
|
|
|
530
529
|
return sendViaITC(service, 'getServiceConfig')
|
|
531
530
|
}
|
|
532
531
|
|
|
532
|
+
async getServiceEnv (id) {
|
|
533
|
+
const service = await this.#getServiceById(id, true)
|
|
534
|
+
|
|
535
|
+
return sendViaITC(service, 'getServiceEnv')
|
|
536
|
+
}
|
|
537
|
+
|
|
533
538
|
async getServiceOpenapiSchema (id) {
|
|
534
539
|
const service = await this.#getServiceById(id, true)
|
|
535
540
|
|
|
@@ -724,6 +729,10 @@ class Runtime extends EventEmitter {
|
|
|
724
729
|
this.emit(status)
|
|
725
730
|
}
|
|
726
731
|
|
|
732
|
+
#showUrl () {
|
|
733
|
+
this.logger.info(`Platformatic is now listening at ${this.#url}`)
|
|
734
|
+
}
|
|
735
|
+
|
|
727
736
|
async #setupService (serviceConfig) {
|
|
728
737
|
if (this.#status === 'stopping' || this.#status === 'closed') return
|
|
729
738
|
|
|
@@ -778,7 +787,9 @@ class Runtime extends EventEmitter {
|
|
|
778
787
|
|
|
779
788
|
// Wait for the next tick so that crashed from the thread are logged first
|
|
780
789
|
setImmediate(() => {
|
|
781
|
-
|
|
790
|
+
if (!config.watch || code !== 0) {
|
|
791
|
+
this.logger.warn(`Service "${id}" unexpectedly exited with code ${code}.`)
|
|
792
|
+
}
|
|
782
793
|
|
|
783
794
|
// Restart the service if it was started
|
|
784
795
|
if (started && this.#status === 'started') {
|
|
@@ -822,6 +833,10 @@ class Runtime extends EventEmitter {
|
|
|
822
833
|
}
|
|
823
834
|
|
|
824
835
|
this.logger?.info(`Service ${id} has been successfully reloaded ...`)
|
|
836
|
+
|
|
837
|
+
if (serviceConfig.entrypoint) {
|
|
838
|
+
this.#showUrl()
|
|
839
|
+
}
|
|
825
840
|
} catch (e) {
|
|
826
841
|
this.logger?.error(e)
|
|
827
842
|
}
|
|
@@ -839,7 +854,7 @@ class Runtime extends EventEmitter {
|
|
|
839
854
|
this.#interceptor.route(id, service)
|
|
840
855
|
|
|
841
856
|
// Store dependencies
|
|
842
|
-
const [{ dependencies }] = await
|
|
857
|
+
const [{ dependencies }] = await waitEventFromITC(service, 'init')
|
|
843
858
|
|
|
844
859
|
if (autoload) {
|
|
845
860
|
serviceConfig.dependencies = dependencies
|
package/lib/schema.js
CHANGED
|
@@ -3,10 +3,37 @@
|
|
|
3
3
|
|
|
4
4
|
const telemetry = require('@platformatic/telemetry').schema
|
|
5
5
|
const {
|
|
6
|
-
schemaComponents: { server }
|
|
6
|
+
schemaComponents: { server, logger }
|
|
7
7
|
} = require('@platformatic/utils')
|
|
8
8
|
|
|
9
|
+
const services = {
|
|
10
|
+
type: 'array',
|
|
11
|
+
items: {
|
|
12
|
+
type: 'object',
|
|
13
|
+
anyOf: [{ required: ['id', 'path'] }, { required: ['id', 'url'] }],
|
|
14
|
+
properties: {
|
|
15
|
+
id: {
|
|
16
|
+
type: 'string'
|
|
17
|
+
},
|
|
18
|
+
path: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
resolvePath: true
|
|
21
|
+
},
|
|
22
|
+
config: {
|
|
23
|
+
type: 'string'
|
|
24
|
+
},
|
|
25
|
+
url: {
|
|
26
|
+
type: 'string'
|
|
27
|
+
},
|
|
28
|
+
useHttp: {
|
|
29
|
+
type: 'boolean'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
9
35
|
const pkg = require('../package.json')
|
|
36
|
+
|
|
10
37
|
const platformaticRuntimeSchema = {
|
|
11
38
|
$id: `https://schemas.platformatic.dev/@platformatic/runtime/${pkg.version}.json`,
|
|
12
39
|
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
@@ -19,6 +46,9 @@ const platformaticRuntimeSchema = {
|
|
|
19
46
|
type: 'string',
|
|
20
47
|
resolvePath: true
|
|
21
48
|
},
|
|
49
|
+
entrypoint: {
|
|
50
|
+
type: 'string'
|
|
51
|
+
},
|
|
22
52
|
autoload: {
|
|
23
53
|
type: 'object',
|
|
24
54
|
additionalProperties: false,
|
|
@@ -56,38 +86,20 @@ const platformaticRuntimeSchema = {
|
|
|
56
86
|
}
|
|
57
87
|
}
|
|
58
88
|
},
|
|
59
|
-
|
|
89
|
+
services,
|
|
90
|
+
web: services,
|
|
91
|
+
logger,
|
|
60
92
|
server,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
},
|
|
64
|
-
watch: {
|
|
93
|
+
restartOnError: {
|
|
94
|
+
default: true,
|
|
65
95
|
anyOf: [
|
|
96
|
+
{ type: 'boolean' },
|
|
66
97
|
{
|
|
67
|
-
type: '
|
|
68
|
-
|
|
69
|
-
{
|
|
70
|
-
type: 'string'
|
|
98
|
+
type: 'number',
|
|
99
|
+
minimum: 100
|
|
71
100
|
}
|
|
72
101
|
]
|
|
73
102
|
},
|
|
74
|
-
inspectorOptions: {
|
|
75
|
-
type: 'object',
|
|
76
|
-
properties: {
|
|
77
|
-
host: {
|
|
78
|
-
type: 'string'
|
|
79
|
-
},
|
|
80
|
-
port: {
|
|
81
|
-
type: 'number'
|
|
82
|
-
},
|
|
83
|
-
breakFirstLine: {
|
|
84
|
-
type: 'boolean'
|
|
85
|
-
},
|
|
86
|
-
watchDisabled: {
|
|
87
|
-
type: 'boolean'
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
103
|
undici: {
|
|
92
104
|
type: 'object',
|
|
93
105
|
properties: {
|
|
@@ -130,6 +142,16 @@ const platformaticRuntimeSchema = {
|
|
|
130
142
|
}
|
|
131
143
|
}
|
|
132
144
|
},
|
|
145
|
+
watch: {
|
|
146
|
+
anyOf: [
|
|
147
|
+
{
|
|
148
|
+
type: 'boolean'
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
type: 'string'
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
},
|
|
133
155
|
managementApi: {
|
|
134
156
|
anyOf: [
|
|
135
157
|
{ type: 'boolean' },
|
|
@@ -138,11 +160,15 @@ const platformaticRuntimeSchema = {
|
|
|
138
160
|
type: 'object',
|
|
139
161
|
properties: {
|
|
140
162
|
logs: {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
163
|
+
type: 'object',
|
|
164
|
+
properties: {
|
|
165
|
+
maxSize: {
|
|
166
|
+
type: 'number',
|
|
167
|
+
minimum: 5,
|
|
168
|
+
default: 200
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
additionalProperties: false
|
|
146
172
|
}
|
|
147
173
|
},
|
|
148
174
|
additionalProperties: false
|
|
@@ -179,43 +205,30 @@ const platformaticRuntimeSchema = {
|
|
|
179
205
|
}
|
|
180
206
|
]
|
|
181
207
|
},
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
{
|
|
187
|
-
type: '
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
properties: {
|
|
198
|
-
id: {
|
|
199
|
-
type: 'string'
|
|
200
|
-
},
|
|
201
|
-
path: {
|
|
202
|
-
type: 'string',
|
|
203
|
-
resolvePath: true
|
|
204
|
-
},
|
|
205
|
-
config: {
|
|
206
|
-
type: 'string'
|
|
207
|
-
},
|
|
208
|
-
url: {
|
|
209
|
-
type: 'string'
|
|
210
|
-
},
|
|
211
|
-
useHttp: {
|
|
212
|
-
type: 'boolean'
|
|
213
|
-
}
|
|
208
|
+
telemetry,
|
|
209
|
+
inspectorOptions: {
|
|
210
|
+
type: 'object',
|
|
211
|
+
properties: {
|
|
212
|
+
host: {
|
|
213
|
+
type: 'string'
|
|
214
|
+
},
|
|
215
|
+
port: {
|
|
216
|
+
type: 'number'
|
|
217
|
+
},
|
|
218
|
+
breakFirstLine: {
|
|
219
|
+
type: 'boolean'
|
|
220
|
+
},
|
|
221
|
+
watchDisabled: {
|
|
222
|
+
type: 'boolean'
|
|
214
223
|
}
|
|
215
224
|
}
|
|
216
225
|
}
|
|
217
226
|
},
|
|
218
|
-
anyOf: [
|
|
227
|
+
anyOf: [
|
|
228
|
+
{ required: ['autoload', 'entrypoint'] },
|
|
229
|
+
{ required: ['services', 'entrypoint'] },
|
|
230
|
+
{ required: ['web', 'entrypoint'] }
|
|
231
|
+
],
|
|
219
232
|
additionalProperties: false,
|
|
220
233
|
$defs: {
|
|
221
234
|
undiciInterceptor: {
|
package/lib/start.js
CHANGED
|
@@ -45,7 +45,13 @@ async function buildRuntime (configManager, env) {
|
|
|
45
45
|
}
|
|
46
46
|
})
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
try {
|
|
49
|
+
await runtime.init()
|
|
50
|
+
} catch (e) {
|
|
51
|
+
await runtime.close()
|
|
52
|
+
throw e
|
|
53
|
+
}
|
|
54
|
+
|
|
49
55
|
return runtime
|
|
50
56
|
}
|
|
51
57
|
|
|
@@ -108,7 +114,7 @@ async function setupAndStartRuntime (config) {
|
|
|
108
114
|
return { address, runtime }
|
|
109
115
|
}
|
|
110
116
|
|
|
111
|
-
async function startCommand (args) {
|
|
117
|
+
async function startCommand (args, throwAllErrors = false, returnRuntime = false) {
|
|
112
118
|
try {
|
|
113
119
|
const config = await loadConfig(
|
|
114
120
|
{
|
|
@@ -132,8 +138,12 @@ async function startCommand (args) {
|
|
|
132
138
|
await runtime.close()
|
|
133
139
|
})
|
|
134
140
|
|
|
135
|
-
return res
|
|
141
|
+
return returnRuntime ? runtime : res
|
|
136
142
|
} catch (err) {
|
|
143
|
+
if (throwAllErrors) {
|
|
144
|
+
throw err
|
|
145
|
+
}
|
|
146
|
+
|
|
137
147
|
if (err.code === 'PLT_CONFIG_NO_CONFIG_FILE_FOUND' && args.length === 1) {
|
|
138
148
|
const config = {
|
|
139
149
|
$schema: `https://schemas.platformatic.dev/@platformatic/service/${pkg.version}.json`,
|
package/lib/upgrade.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const { join } = require('node:path')
|
|
4
4
|
|
|
5
|
-
const pkg = require('../package.json')
|
|
6
|
-
|
|
7
5
|
module.exports = async function upgrade (config, version) {
|
|
8
6
|
const { semgrator } = await import('semgrator')
|
|
9
7
|
|
|
@@ -20,7 +18,5 @@ module.exports = async function upgrade (config, version) {
|
|
|
20
18
|
result = updated.result
|
|
21
19
|
}
|
|
22
20
|
|
|
23
|
-
result.$schema = `https://schemas.platformatic.dev/@platformatic/runtime/${pkg.version}.json`
|
|
24
|
-
|
|
25
21
|
return result
|
|
26
22
|
}
|
package/lib/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ const { join } = require('node:path')
|
|
|
7
7
|
const {
|
|
8
8
|
Store,
|
|
9
9
|
loadConfig: pltConfigLoadConfig,
|
|
10
|
-
loadEmptyConfig: pltConfigLoadEmptyConfig
|
|
10
|
+
loadEmptyConfig: pltConfigLoadEmptyConfig
|
|
11
11
|
} = require('@platformatic/config')
|
|
12
12
|
|
|
13
13
|
const { platformaticRuntime } = require('./config')
|
|
@@ -37,6 +37,22 @@ async function loadConfig (minimistConfig, args, overrides, replaceEnv = true) {
|
|
|
37
37
|
const { default: platformaticBasic } = await import('@platformatic/basic')
|
|
38
38
|
const store = new Store()
|
|
39
39
|
store.add(platformaticRuntime)
|
|
40
|
+
|
|
41
|
+
const id = platformaticRuntime.schema.$id.replace('@platformatic/runtime', 'wattpm')
|
|
42
|
+
const schema = {
|
|
43
|
+
...platformaticRuntime.schema,
|
|
44
|
+
$id: id
|
|
45
|
+
}
|
|
46
|
+
const configManagerConfig = {
|
|
47
|
+
...platformaticRuntime.configManagerConfig,
|
|
48
|
+
schema
|
|
49
|
+
}
|
|
50
|
+
const wattpm = {
|
|
51
|
+
...platformaticRuntime,
|
|
52
|
+
schema,
|
|
53
|
+
configManagerConfig
|
|
54
|
+
}
|
|
55
|
+
store.add(wattpm)
|
|
40
56
|
store.add(platformaticBasic)
|
|
41
57
|
|
|
42
58
|
return pltConfigLoadConfig(minimistConfig, args, store, overrides, replaceEnv)
|
|
@@ -54,5 +70,5 @@ module.exports = {
|
|
|
54
70
|
getRuntimeTmpDir,
|
|
55
71
|
getServiceUrl,
|
|
56
72
|
loadConfig,
|
|
57
|
-
loadEmptyConfig
|
|
73
|
+
loadEmptyConfig
|
|
58
74
|
}
|
package/lib/versions/v2.0.0.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const pkg = require('../../package.json')
|
|
4
|
+
|
|
3
5
|
module.exports = {
|
|
4
6
|
version: '1.99.0', // This is to account alpha versions as well
|
|
5
7
|
up: function (config) {
|
|
@@ -12,6 +14,13 @@ module.exports = {
|
|
|
12
14
|
delete config.hotReload
|
|
13
15
|
}
|
|
14
16
|
|
|
17
|
+
config.$schema = `https://schemas.platformatic.dev/@platformatic/runtime/${pkg.version}.json`
|
|
18
|
+
|
|
19
|
+
if (config.server?.logger) {
|
|
20
|
+
config.logger = config.server.logger
|
|
21
|
+
delete config.server.logger
|
|
22
|
+
}
|
|
23
|
+
|
|
15
24
|
return config
|
|
16
|
-
}
|
|
25
|
+
}
|
|
17
26
|
}
|
package/lib/worker/app.js
CHANGED
|
@@ -20,7 +20,7 @@ class PlatformaticApp extends EventEmitter {
|
|
|
20
20
|
#debouncedRestart
|
|
21
21
|
#context
|
|
22
22
|
|
|
23
|
-
constructor (appConfig, telemetryConfig, serverConfig, hasManagementApi, watch
|
|
23
|
+
constructor (appConfig, telemetryConfig, loggerConfig, serverConfig, metricsConfig, hasManagementApi, watch) {
|
|
24
24
|
super()
|
|
25
25
|
this.appConfig = appConfig
|
|
26
26
|
this.#watch = watch
|
|
@@ -38,6 +38,7 @@ class PlatformaticApp extends EventEmitter {
|
|
|
38
38
|
isProduction: this.appConfig.isProduction,
|
|
39
39
|
telemetryConfig,
|
|
40
40
|
metricsConfig,
|
|
41
|
+
loggerConfig,
|
|
41
42
|
serverConfig,
|
|
42
43
|
hasManagementApi: !!hasManagementApi,
|
|
43
44
|
localServiceEnvVars: this.appConfig.localServiceEnvVars
|
|
@@ -102,16 +103,17 @@ class PlatformaticApp extends EventEmitter {
|
|
|
102
103
|
|
|
103
104
|
const metricsConfig = this.#context.metricsConfig
|
|
104
105
|
if (metricsConfig !== false) {
|
|
105
|
-
this.#metricsRegistry = await collectMetrics(
|
|
106
|
-
this.stackable,
|
|
107
|
-
this.appConfig.id,
|
|
108
|
-
metricsConfig
|
|
109
|
-
)
|
|
106
|
+
this.#metricsRegistry = await collectMetrics(this.stackable, this.appConfig.id, metricsConfig)
|
|
110
107
|
}
|
|
111
108
|
|
|
112
109
|
this.#updateDispatcher()
|
|
113
110
|
} catch (err) {
|
|
114
|
-
|
|
111
|
+
if (err.validationErrors) {
|
|
112
|
+
console.error('Validation errors:', err.validationErrors)
|
|
113
|
+
process.exit(1)
|
|
114
|
+
} else {
|
|
115
|
+
this.#logAndExit(err)
|
|
116
|
+
}
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
119
|
|
|
@@ -183,9 +185,7 @@ class PlatformaticApp extends EventEmitter {
|
|
|
183
185
|
async getMetrics ({ format }) {
|
|
184
186
|
if (!this.#metricsRegistry) return null
|
|
185
187
|
|
|
186
|
-
return format === 'json'
|
|
187
|
-
? this.#metricsRegistry.getMetricsAsJSON()
|
|
188
|
-
: this.#metricsRegistry.metrics()
|
|
188
|
+
return format === 'json' ? this.#metricsRegistry.getMetricsAsJSON() : this.#metricsRegistry.metrics()
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
#fetchServiceUrl (key, { parent, context: service }) {
|
|
@@ -10,6 +10,7 @@ const defaultStackable = {
|
|
|
10
10
|
getUrl: () => null,
|
|
11
11
|
updateContext: () => {},
|
|
12
12
|
getConfig: () => null,
|
|
13
|
+
getEnv: () => null,
|
|
13
14
|
getInfo: () => null,
|
|
14
15
|
getDispatchFunc: () => null,
|
|
15
16
|
getOpenapiSchema: () => null,
|
|
@@ -17,7 +18,7 @@ const defaultStackable = {
|
|
|
17
18
|
getMeta: () => ({}),
|
|
18
19
|
collectMetrics: () => ({
|
|
19
20
|
defaultMetrics: true,
|
|
20
|
-
httpMetrics: true
|
|
21
|
+
httpMetrics: true
|
|
21
22
|
}),
|
|
22
23
|
inject: () => {
|
|
23
24
|
throw new Error('Stackable inject not implemented')
|
|
@@ -26,7 +27,7 @@ const defaultStackable = {
|
|
|
26
27
|
console.log(message)
|
|
27
28
|
},
|
|
28
29
|
getBootstrapDependencies: () => [],
|
|
29
|
-
getWatchConfig: () => ({ enabled: false })
|
|
30
|
+
getWatchConfig: () => ({ enabled: false })
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
module.exports = defaultStackable
|
package/lib/worker/itc.js
CHANGED
|
@@ -9,14 +9,14 @@ const { Unpromise } = require('@watchable/unpromise')
|
|
|
9
9
|
const errors = require('../errors')
|
|
10
10
|
const { kITC, kId } = require('./symbols')
|
|
11
11
|
|
|
12
|
-
async function
|
|
12
|
+
async function safeHandleInITC (worker, fn) {
|
|
13
13
|
try {
|
|
14
14
|
// Make sure to catch when the worker exits, otherwise we're stuck forever
|
|
15
15
|
const ac = new AbortController()
|
|
16
16
|
let exitCode
|
|
17
17
|
|
|
18
18
|
const response = await Unpromise.race([
|
|
19
|
-
|
|
19
|
+
fn(),
|
|
20
20
|
once(worker, 'exit', { signal: ac.signal }).then(([code]) => {
|
|
21
21
|
exitCode = code
|
|
22
22
|
})
|
|
@@ -42,6 +42,14 @@ async function sendViaITC (worker, name, message) {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
async function sendViaITC (worker, name, message) {
|
|
46
|
+
return safeHandleInITC(worker, () => worker[kITC].send(name, message))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function waitEventFromITC (worker, event) {
|
|
50
|
+
return safeHandleInITC(worker, () => once(worker[kITC], event))
|
|
51
|
+
}
|
|
52
|
+
|
|
45
53
|
function setupITC (app, service, dispatcher) {
|
|
46
54
|
const itc = new ITC({
|
|
47
55
|
name: app.appConfig.id + '-worker',
|
|
@@ -101,6 +109,11 @@ function setupITC (app, service, dispatcher) {
|
|
|
101
109
|
return JSON.parse(JSON.stringify(current))
|
|
102
110
|
},
|
|
103
111
|
|
|
112
|
+
async getServiceEnv () {
|
|
113
|
+
// Remove all undefined keys from the config
|
|
114
|
+
return JSON.parse(JSON.stringify({ ...process.env, ...(await app.stackable.getEnv()) }))
|
|
115
|
+
},
|
|
116
|
+
|
|
104
117
|
async getServiceOpenAPISchema () {
|
|
105
118
|
try {
|
|
106
119
|
return await app.stackable.getOpenapiSchema()
|
|
@@ -146,4 +159,4 @@ function setupITC (app, service, dispatcher) {
|
|
|
146
159
|
return itc
|
|
147
160
|
}
|
|
148
161
|
|
|
149
|
-
module.exports = { sendViaITC, setupITC }
|
|
162
|
+
module.exports = { sendViaITC, setupITC, waitEventFromITC }
|
package/lib/worker/main.js
CHANGED
|
@@ -12,7 +12,12 @@ const { wire } = require('undici-thread-interceptor')
|
|
|
12
12
|
const { PlatformaticApp } = require('./app')
|
|
13
13
|
const { setupITC } = require('./itc')
|
|
14
14
|
const loadInterceptors = require('./interceptors')
|
|
15
|
-
const {
|
|
15
|
+
const {
|
|
16
|
+
MessagePortWritable,
|
|
17
|
+
createPinoWritable,
|
|
18
|
+
executeWithTimeout,
|
|
19
|
+
ensureLoggableError
|
|
20
|
+
} = require('@platformatic/utils')
|
|
16
21
|
const { kId, kITC } = require('./symbols')
|
|
17
22
|
|
|
18
23
|
process.on('uncaughtException', handleUnhandled.bind(null, 'uncaught exception'))
|
|
@@ -27,7 +32,7 @@ globalThis.platformatic = Object.assign(globalThis.platformatic ?? {}, { logger:
|
|
|
27
32
|
|
|
28
33
|
function handleUnhandled (type, err) {
|
|
29
34
|
globalThis.platformatic.logger.error(
|
|
30
|
-
{ err:
|
|
35
|
+
{ err: ensureLoggableError(err) },
|
|
31
36
|
`Service ${workerData.serviceConfig.id} threw an ${type}.`
|
|
32
37
|
)
|
|
33
38
|
|
|
@@ -106,10 +111,11 @@ async function main () {
|
|
|
106
111
|
app = new PlatformaticApp(
|
|
107
112
|
service,
|
|
108
113
|
telemetryConfig,
|
|
114
|
+
config.logger,
|
|
109
115
|
serverConfig,
|
|
116
|
+
config.metrics,
|
|
110
117
|
!!config.managementApi,
|
|
111
|
-
!!config.watch
|
|
112
|
-
config.metrics
|
|
118
|
+
!!config.watch
|
|
113
119
|
)
|
|
114
120
|
|
|
115
121
|
await app.init()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/runtime",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/platformatic/platformatic#readme",
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@fastify/express": "^
|
|
21
|
-
"@fastify/formbody": "^
|
|
20
|
+
"@fastify/express": "^4.0.0",
|
|
21
|
+
"@fastify/formbody": "^8.0.0",
|
|
22
22
|
"borp": "^0.17.0",
|
|
23
23
|
"c8": "^10.0.0",
|
|
24
24
|
"eslint": "9",
|
|
@@ -28,21 +28,21 @@
|
|
|
28
28
|
"get-port": "^7.1.0",
|
|
29
29
|
"json-schema-to-typescript": "^15.0.0",
|
|
30
30
|
"neostandard": "^0.11.1",
|
|
31
|
-
"pino-abstract-transport": "^
|
|
31
|
+
"pino-abstract-transport": "^2.0.0",
|
|
32
32
|
"split2": "^4.2.0",
|
|
33
33
|
"tsd": "^0.31.0",
|
|
34
34
|
"typescript": "^5.5.4",
|
|
35
35
|
"undici-oidc-interceptor": "^0.5.0",
|
|
36
36
|
"why-is-node-running": "^2.2.2",
|
|
37
|
-
"@platformatic/composer": "2.0.0
|
|
38
|
-
"@platformatic/
|
|
39
|
-
"@platformatic/
|
|
40
|
-
"@platformatic/sql-
|
|
41
|
-
"@platformatic/
|
|
37
|
+
"@platformatic/composer": "2.0.0",
|
|
38
|
+
"@platformatic/db": "2.0.0",
|
|
39
|
+
"@platformatic/service": "2.0.0",
|
|
40
|
+
"@platformatic/sql-graphql": "2.0.0",
|
|
41
|
+
"@platformatic/sql-mapper": "2.0.0"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@fastify/error": "^
|
|
45
|
-
"@fastify/websocket": "^
|
|
44
|
+
"@fastify/error": "^4.0.0",
|
|
45
|
+
"@fastify/websocket": "^11.0.0",
|
|
46
46
|
"@hapi/topo": "^6.0.2",
|
|
47
47
|
"@platformatic/http-metrics": "^0.1.0",
|
|
48
48
|
"@watchable/unpromise": "^1.0.2",
|
|
@@ -55,31 +55,30 @@
|
|
|
55
55
|
"dotenv-tool": "^0.1.1",
|
|
56
56
|
"es-main": "^1.3.0",
|
|
57
57
|
"fastest-levenshtein": "^1.0.16",
|
|
58
|
-
"fastify": "^
|
|
59
|
-
"fastify-undici-dispatcher": "^0.6.0",
|
|
58
|
+
"fastify": "^5.0.0",
|
|
60
59
|
"graphql": "^16.8.1",
|
|
61
60
|
"help-me": "^5.0.0",
|
|
62
61
|
"minimist": "^1.2.8",
|
|
63
62
|
"pino": "^8.19.0",
|
|
64
63
|
"pino-pretty": "^11.0.0",
|
|
65
|
-
"pino-roll": "^
|
|
64
|
+
"pino-roll": "^2.0.0",
|
|
66
65
|
"prom-client": "^15.1.2",
|
|
67
66
|
"semgrator": "^0.3.0",
|
|
68
67
|
"tail-file-stream": "^0.2.0",
|
|
69
68
|
"undici": "^6.9.0",
|
|
70
69
|
"undici-thread-interceptor": "^0.6.1",
|
|
71
70
|
"ws": "^8.16.0",
|
|
72
|
-
"@platformatic/basic": "2.0.0
|
|
73
|
-
"@platformatic/config": "2.0.0
|
|
74
|
-
"@platformatic/generators": "2.0.0
|
|
75
|
-
"@platformatic/itc": "2.0.0
|
|
76
|
-
"@platformatic/telemetry": "2.0.0
|
|
77
|
-
"@platformatic/ts-compiler": "2.0.0
|
|
78
|
-
"@platformatic/utils": "2.0.0
|
|
71
|
+
"@platformatic/basic": "2.0.0",
|
|
72
|
+
"@platformatic/config": "2.0.0",
|
|
73
|
+
"@platformatic/generators": "2.0.0",
|
|
74
|
+
"@platformatic/itc": "2.0.0",
|
|
75
|
+
"@platformatic/telemetry": "2.0.0",
|
|
76
|
+
"@platformatic/ts-compiler": "2.0.0",
|
|
77
|
+
"@platformatic/utils": "2.0.0"
|
|
79
78
|
},
|
|
80
79
|
"scripts": {
|
|
81
80
|
"test": "npm run lint && borp --concurrency=1 --timeout=180000 && tsd",
|
|
82
|
-
"coverage": "npm run lint && borp -X
|
|
81
|
+
"coverage": "npm run lint && borp -X fixtures -X test -C --concurrency=1 --timeout=180000 && tsd",
|
|
83
82
|
"gen-schema": "node lib/schema.js > schema.json",
|
|
84
83
|
"gen-types": "json2ts > config.d.ts < schema.json",
|
|
85
84
|
"build": "pnpm run gen-schema && pnpm run gen-types",
|