@platformatic/runtime 2.10.0 → 2.11.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 CHANGED
@@ -5,7 +5,7 @@
5
5
  * and run json-schema-to-typescript to regenerate this file.
6
6
  */
7
7
 
8
- export type HttpsSchemasPlatformaticDevPlatformaticRuntime2100Json = {
8
+ export type HttpsSchemasPlatformaticDevPlatformaticRuntime2110Json = {
9
9
  [k: string]: unknown;
10
10
  } & {
11
11
  $schema?: string;
@@ -104,6 +104,7 @@ export type HttpsSchemasPlatformaticDevPlatformaticRuntime2100Json = {
104
104
  )[];
105
105
  };
106
106
  };
107
+ startTimeout?: number;
107
108
  restartOnError?: boolean | number;
108
109
  gracefulShutdown?: {
109
110
  runtime: number | string;
package/lib/errors.js CHANGED
@@ -13,6 +13,7 @@ module.exports = {
13
13
  UnknownRuntimeAPICommandError: createError(`${ERROR_PREFIX}_UNKNOWN_RUNTIME_API_COMMAND`, 'Unknown Runtime API command "%s"'),
14
14
  ServiceNotFoundError: createError(`${ERROR_PREFIX}_SERVICE_NOT_FOUND`, 'Service %s not found. Available services are: %s'),
15
15
  ServiceNotStartedError: createError(`${ERROR_PREFIX}_SERVICE_NOT_STARTED`, "Service with id '%s' is not started"),
16
+ ServiceStartTimeoutError: createError(`${ERROR_PREFIX}_SERVICE_START_TIMEOUT`, "Service with id '%s' failed to start in %dms."),
16
17
  FailedToRetrieveOpenAPISchemaError: createError(`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_OPENAPI_SCHEMA`, 'Failed to retrieve OpenAPI schema for service with id "%s": %s'),
17
18
  FailedToRetrieveGraphQLSchemaError: createError(`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_GRAPHQL_SCHEMA`, 'Failed to retrieve GraphQL schema for service with id "%s": %s'),
18
19
  FailedToRetrieveMetaError: createError(`${ERROR_PREFIX}_FAILED_TO_RETRIEVE_META`, 'Failed to retrieve metadata for service with id "%s": %s'),
package/lib/runtime.js CHANGED
@@ -973,7 +973,19 @@ class Runtime extends EventEmitter {
973
973
  worker[kWorkerStatus] = 'starting'
974
974
 
975
975
  try {
976
- const workerUrl = await sendViaITC(worker, 'start')
976
+ let workerUrl
977
+ if (config.startTimeout > 0) {
978
+ workerUrl = await executeWithTimeout(sendViaITC(worker, 'start'), config.startTimeout)
979
+
980
+ if (workerUrl === 'timeout') {
981
+ this.logger.info(`The ${label} failed to start in ${config.startTimeout}ms. Forcefully killing the thread.`)
982
+ worker.terminate()
983
+ throw new errors.ServiceStartTimeoutError(id, config.startTimeout)
984
+ }
985
+ } else {
986
+ workerUrl = await sendViaITC(worker, 'start')
987
+ }
988
+
977
989
  if (workerUrl) {
978
990
  this.#url = workerUrl
979
991
  }
@@ -986,9 +998,12 @@ class Runtime extends EventEmitter {
986
998
 
987
999
  const { enabled, gracePeriod } = worker[kConfig].health
988
1000
  if (enabled && config.restartOnError > 0) {
989
- worker[kHealthCheckTimer] = setTimeout(() => {
990
- this.#setupHealthCheck(worker, label)
991
- }, gracePeriod > 0 ? gracePeriod : 1)
1001
+ worker[kHealthCheckTimer] = setTimeout(
1002
+ () => {
1003
+ this.#setupHealthCheck(worker, label)
1004
+ },
1005
+ gracePeriod > 0 ? gracePeriod : 1
1006
+ )
992
1007
  }
993
1008
  } catch (error) {
994
1009
  // TODO: handle port allocation error here
@@ -1002,7 +1017,9 @@ class Runtime extends EventEmitter {
1002
1017
  await worker.terminate()
1003
1018
  }
1004
1019
 
1005
- this.logger.error({ err: ensureLoggableError(error) }, `Failed to start ${label}.`)
1020
+ if (error.code !== 'PLT_RUNTIME_SERVICE_START_TIMEOUT') {
1021
+ this.logger.error({ err: ensureLoggableError(error) }, `Failed to start ${label}.`)
1022
+ }
1006
1023
 
1007
1024
  const restartOnError = config.restartOnError
1008
1025
 
package/lib/schema.js CHANGED
@@ -108,6 +108,11 @@ const platformaticRuntimeSchema = {
108
108
  web: services,
109
109
  logger,
110
110
  server,
111
+ startTimeout: {
112
+ default: 30000,
113
+ type: 'number',
114
+ minimum: 0
115
+ },
111
116
  restartOnError: {
112
117
  default: true,
113
118
  anyOf: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "2.10.0",
3
+ "version": "2.11.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -35,12 +35,12 @@
35
35
  "typescript": "^5.5.4",
36
36
  "undici-oidc-interceptor": "^0.5.0",
37
37
  "why-is-node-running": "^2.2.2",
38
- "@platformatic/composer": "2.10.0",
39
- "@platformatic/db": "2.10.0",
40
- "@platformatic/node": "2.10.0",
41
- "@platformatic/service": "2.10.0",
42
- "@platformatic/sql-mapper": "2.10.0",
43
- "@platformatic/sql-graphql": "2.10.0"
38
+ "@platformatic/composer": "2.11.0",
39
+ "@platformatic/db": "2.11.0",
40
+ "@platformatic/service": "2.11.0",
41
+ "@platformatic/node": "2.11.0",
42
+ "@platformatic/sql-graphql": "2.11.0",
43
+ "@platformatic/sql-mapper": "2.11.0"
44
44
  },
45
45
  "dependencies": {
46
46
  "@fastify/error": "^4.0.0",
@@ -67,17 +67,16 @@
67
67
  "prom-client": "^15.1.2",
68
68
  "semgrator": "^0.3.0",
69
69
  "tail-file-stream": "^0.2.0",
70
- "thread-cpu-usage": "^0.2.0",
71
70
  "undici": "^6.9.0",
72
71
  "undici-thread-interceptor": "^0.8.0",
73
72
  "ws": "^8.16.0",
74
- "@platformatic/basic": "2.10.0",
75
- "@platformatic/generators": "2.10.0",
76
- "@platformatic/config": "2.10.0",
77
- "@platformatic/itc": "2.10.0",
78
- "@platformatic/telemetry": "2.10.0",
79
- "@platformatic/utils": "2.10.0",
80
- "@platformatic/ts-compiler": "2.10.0"
73
+ "@platformatic/basic": "2.11.0",
74
+ "@platformatic/config": "2.11.0",
75
+ "@platformatic/itc": "2.11.0",
76
+ "@platformatic/generators": "2.11.0",
77
+ "@platformatic/telemetry": "2.11.0",
78
+ "@platformatic/ts-compiler": "2.11.0",
79
+ "@platformatic/utils": "2.11.0"
81
80
  },
82
81
  "scripts": {
83
82
  "test": "npm run lint && borp --concurrency=1 --timeout=300000 && tsd",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/runtime/2.10.0.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/runtime/2.11.0.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "type": "object",
5
5
  "properties": {
@@ -654,6 +654,11 @@
654
654
  },
655
655
  "additionalProperties": false
656
656
  },
657
+ "startTimeout": {
658
+ "default": 30000,
659
+ "type": "number",
660
+ "minimum": 0
661
+ },
657
662
  "restartOnError": {
658
663
  "default": true,
659
664
  "anyOf": [