@contember/engine-http 2.2.0-alpha.7 → 2.2.0-alpha.9
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/CLAUDE.md +1 -1
- package/dist/development/src/MasterContainer.cjs +4 -2
- package/dist/development/src/MasterContainer.cjs.map +1 -1
- package/dist/development/src/MasterContainer.js +4 -2
- package/dist/development/src/MasterContainer.js.map +1 -1
- package/dist/development/src/application/application.cjs +1 -1
- package/dist/development/src/application/application.cjs.map +1 -1
- package/dist/development/src/application/application.js +1 -1
- package/dist/development/src/application/application.js.map +1 -1
- package/dist/development/src/application/forceHttpOk.cjs +2 -9
- package/dist/development/src/application/forceHttpOk.cjs.map +1 -1
- package/dist/development/src/application/forceHttpOk.js +2 -9
- package/dist/development/src/application/forceHttpOk.js.map +1 -1
- package/dist/development/src/config/configSchema.cjs +3 -0
- package/dist/development/src/config/configSchema.cjs.map +1 -1
- package/dist/development/src/config/configSchema.js +3 -0
- package/dist/development/src/config/configSchema.js.map +1 -1
- package/dist/development/src/config/configTemplate.cjs +2 -0
- package/dist/development/src/config/configTemplate.cjs.map +1 -1
- package/dist/development/src/config/configTemplate.js +2 -0
- package/dist/development/src/config/configTemplate.js.map +1 -1
- package/dist/development/src/content/ContentApiControllerFactory.cjs +11 -3
- package/dist/development/src/content/ContentApiControllerFactory.cjs.map +1 -1
- package/dist/development/src/content/ContentApiControllerFactory.js +11 -3
- package/dist/development/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs +26 -22
- package/dist/development/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/development/src/projectGroup/ProjectGroupContainer.js +26 -22
- package/dist/development/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/development/src/utils/serverTermination.cjs +5 -1
- package/dist/development/src/utils/serverTermination.cjs.map +1 -1
- package/dist/development/src/utils/serverTermination.js +5 -1
- package/dist/development/src/utils/serverTermination.js.map +1 -1
- package/dist/development/src/utils/truthyHeader.cjs +13 -0
- package/dist/development/src/utils/truthyHeader.cjs.map +1 -0
- package/dist/development/src/utils/truthyHeader.js +13 -0
- package/dist/development/src/utils/truthyHeader.js.map +1 -0
- package/dist/production/src/MasterContainer.cjs +4 -2
- package/dist/production/src/MasterContainer.cjs.map +1 -1
- package/dist/production/src/MasterContainer.js +4 -2
- package/dist/production/src/MasterContainer.js.map +1 -1
- package/dist/production/src/application/application.cjs +1 -1
- package/dist/production/src/application/application.cjs.map +1 -1
- package/dist/production/src/application/application.js +1 -1
- package/dist/production/src/application/application.js.map +1 -1
- package/dist/production/src/application/forceHttpOk.cjs +2 -9
- package/dist/production/src/application/forceHttpOk.cjs.map +1 -1
- package/dist/production/src/application/forceHttpOk.js +2 -9
- package/dist/production/src/application/forceHttpOk.js.map +1 -1
- package/dist/production/src/config/configSchema.cjs +3 -0
- package/dist/production/src/config/configSchema.cjs.map +1 -1
- package/dist/production/src/config/configSchema.js +3 -0
- package/dist/production/src/config/configSchema.js.map +1 -1
- package/dist/production/src/config/configTemplate.cjs +2 -0
- package/dist/production/src/config/configTemplate.cjs.map +1 -1
- package/dist/production/src/config/configTemplate.js +2 -0
- package/dist/production/src/config/configTemplate.js.map +1 -1
- package/dist/production/src/content/ContentApiControllerFactory.cjs +11 -3
- package/dist/production/src/content/ContentApiControllerFactory.cjs.map +1 -1
- package/dist/production/src/content/ContentApiControllerFactory.js +11 -3
- package/dist/production/src/content/ContentApiControllerFactory.js.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs +26 -22
- package/dist/production/src/projectGroup/ProjectGroupContainer.cjs.map +1 -1
- package/dist/production/src/projectGroup/ProjectGroupContainer.js +26 -22
- package/dist/production/src/projectGroup/ProjectGroupContainer.js.map +1 -1
- package/dist/production/src/utils/serverTermination.cjs +5 -1
- package/dist/production/src/utils/serverTermination.cjs.map +1 -1
- package/dist/production/src/utils/serverTermination.js +5 -1
- package/dist/production/src/utils/serverTermination.js.map +1 -1
- package/dist/production/src/utils/truthyHeader.cjs +13 -0
- package/dist/production/src/utils/truthyHeader.cjs.map +1 -0
- package/dist/production/src/utils/truthyHeader.js +13 -0
- package/dist/production/src/utils/truthyHeader.js.map +1 -0
- package/dist/tests/cases/unit/forcePrimary.test.d.ts +2 -0
- package/dist/tests/cases/unit/forcePrimary.test.d.ts.map +1 -0
- package/dist/tests/cases/unit/serverTermination.fixture.d.ts +2 -0
- package/dist/tests/cases/unit/serverTermination.fixture.d.ts.map +1 -0
- package/dist/tests/cases/unit/serverTermination.test.d.ts +2 -0
- package/dist/tests/cases/unit/serverTermination.test.d.ts.map +1 -0
- package/dist/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/MasterContainer.d.ts +2 -0
- package/dist/types/MasterContainer.d.ts.map +1 -1
- package/dist/types/application/forceHttpOk.d.ts.map +1 -1
- package/dist/types/config/configSchema.d.ts +5 -0
- package/dist/types/config/configSchema.d.ts.map +1 -1
- package/dist/types/config/configTemplate.d.ts.map +1 -1
- package/dist/types/content/ContentApiControllerFactory.d.ts +2 -1
- package/dist/types/content/ContentApiControllerFactory.d.ts.map +1 -1
- package/dist/types/projectGroup/ProjectGroupContainer.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/dist/types/utils/serverTermination.d.ts +9 -1
- package/dist/types/utils/serverTermination.d.ts.map +1 -1
- package/dist/types/utils/truthyHeader.d.ts +3 -0
- package/dist/types/utils/truthyHeader.d.ts.map +1 -0
- package/package.json +15 -15
- package/src/MasterContainer.ts +2 -0
- package/src/application/application.ts +1 -1
- package/src/application/forceHttpOk.ts +2 -10
- package/src/config/configSchema.ts +3 -0
- package/src/config/configTemplate.ts +2 -0
- package/src/content/ContentApiControllerFactory.ts +12 -2
- package/src/projectGroup/ProjectGroupContainer.ts +28 -24
- package/src/utils/serverTermination.ts +19 -1
- package/src/utils/truthyHeader.ts +12 -0
- package/tests/cases/unit/forcePrimary.test.ts +293 -0
- package/tests/cases/unit/serverConfig.test.ts +16 -0
- package/tests/cases/unit/serverTermination.fixture.ts +13 -0
- package/tests/cases/unit/serverTermination.test.ts +49 -0
|
@@ -8,6 +8,14 @@ export type TerminationJob = (args: {
|
|
|
8
8
|
signal: keyof typeof signals;
|
|
9
9
|
code: number;
|
|
10
10
|
}) => Promise<void>;
|
|
11
|
-
export
|
|
11
|
+
export interface ProcessTerminationOptions {
|
|
12
|
+
/**
|
|
13
|
+
* How long the process keeps serving after SIGTERM before the jobs run. An orchestrator stops routing to
|
|
14
|
+
* a process only some time after signalling it, so draining at once refuses what is still on its way.
|
|
15
|
+
* SIGINT and SIGHUP never wait.
|
|
16
|
+
*/
|
|
17
|
+
readonly sigtermDelayMs?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare const listenOnProcessTermination: (jobs: TerminationJob[], logger: Logger, { sigtermDelayMs }?: ProcessTerminationOptions) => void;
|
|
12
20
|
export {};
|
|
13
21
|
//# sourceMappingURL=serverTermination.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverTermination.d.ts","sourceRoot":"","sources":["../../../src/utils/serverTermination.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,QAAA,MAAM,OAAO;IACZ,MAAM;IACN,MAAM;IACN,OAAO;CACP,CAAA;AACD,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,OAAO,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"serverTermination.d.ts","sourceRoot":"","sources":["../../../src/utils/serverTermination.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE1C,QAAA,MAAM,OAAO;IACZ,MAAM;IACN,MAAM;IACN,OAAO;CACP,CAAA;AACD,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,OAAO,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;AAEpG,MAAM,WAAW,yBAAyB;IACzC;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAChC;AAED,eAAO,MAAM,0BAA0B,SAChC,cAAc,EAAE,UACd,MAAM,uBACU,yBAAyB,SAcjD,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truthyHeader.d.ts","sourceRoot":"","sources":["../../../src/utils/truthyHeader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAI3C,eAAO,MAAM,cAAc,YAAa,eAAe,UAAU,MAAM,KAAG,OAOzE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/engine-http",
|
|
3
|
-
"version": "2.2.0-alpha.
|
|
3
|
+
"version": "2.2.0-alpha.9",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/production/index.js",
|
|
6
6
|
"typings": "./dist/types/index.d.ts",
|
|
@@ -26,20 +26,20 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@contember/config-loader": "2.2.0-alpha.
|
|
30
|
-
"@contember/database": "2.2.0-alpha.
|
|
31
|
-
"@contember/database-migrations": "2.2.0-alpha.
|
|
32
|
-
"@contember/dic": "2.2.0-alpha.
|
|
33
|
-
"@contember/engine-common": "2.2.0-alpha.
|
|
34
|
-
"@contember/engine-content-api": "2.2.0-alpha.
|
|
35
|
-
"@contember/engine-system-api": "2.2.0-alpha.
|
|
36
|
-
"@contember/engine-tenant-api": "2.2.0-alpha.
|
|
37
|
-
"@contember/graphql-utils": "2.2.0-alpha.
|
|
38
|
-
"@contember/logger": "2.2.0-alpha.
|
|
39
|
-
"@contember/schema": "2.2.0-alpha.
|
|
40
|
-
"@contember/schema-migrations": "2.2.0-alpha.
|
|
41
|
-
"@contember/schema-utils": "2.2.0-alpha.
|
|
42
|
-
"@contember/typesafe": "2.2.0-alpha.
|
|
29
|
+
"@contember/config-loader": "2.2.0-alpha.9",
|
|
30
|
+
"@contember/database": "2.2.0-alpha.9",
|
|
31
|
+
"@contember/database-migrations": "2.2.0-alpha.9",
|
|
32
|
+
"@contember/dic": "2.2.0-alpha.9",
|
|
33
|
+
"@contember/engine-common": "2.2.0-alpha.9",
|
|
34
|
+
"@contember/engine-content-api": "2.2.0-alpha.9",
|
|
35
|
+
"@contember/engine-system-api": "2.2.0-alpha.9",
|
|
36
|
+
"@contember/engine-tenant-api": "2.2.0-alpha.9",
|
|
37
|
+
"@contember/graphql-utils": "2.2.0-alpha.9",
|
|
38
|
+
"@contember/logger": "2.2.0-alpha.9",
|
|
39
|
+
"@contember/schema": "2.2.0-alpha.9",
|
|
40
|
+
"@contember/schema-migrations": "2.2.0-alpha.9",
|
|
41
|
+
"@contember/schema-utils": "2.2.0-alpha.9",
|
|
42
|
+
"@contember/typesafe": "2.2.0-alpha.9",
|
|
43
43
|
"@graphql-tools/merge": "^9.1.7",
|
|
44
44
|
"@graphql-tools/schema": "^10.0.31",
|
|
45
45
|
"@koa/cors": "^5.0.0",
|
package/src/MasterContainer.ts
CHANGED
|
@@ -226,6 +226,7 @@ export class MasterContainerFactory {
|
|
|
226
226
|
contentQueryHandlerFactory,
|
|
227
227
|
graphQlSchemaFactory,
|
|
228
228
|
testTransactionService,
|
|
229
|
+
serverConfig,
|
|
229
230
|
},
|
|
230
231
|
) =>
|
|
231
232
|
new ContentApiControllerFactory(
|
|
@@ -235,6 +236,7 @@ export class MasterContainerFactory {
|
|
|
235
236
|
projectContextResolver,
|
|
236
237
|
graphQlSchemaFactory,
|
|
237
238
|
testTransactionService,
|
|
239
|
+
serverConfig.contentApi?.forcePrimaryHeader ?? false,
|
|
238
240
|
),
|
|
239
241
|
)
|
|
240
242
|
.addService('tenantApiMiddlewareFactory', () => new TenantApiMiddlewareFactory())
|
|
@@ -95,7 +95,7 @@ export class Application {
|
|
|
95
95
|
koa.use(bodyParser({
|
|
96
96
|
jsonLimit: this.serverConfig.http?.requestBodySize || '1mb',
|
|
97
97
|
}))
|
|
98
|
-
koa.use(corsMiddleware())
|
|
98
|
+
koa.use(corsMiddleware({ exposeHeaders: ['X-Contember-Mutation'] }))
|
|
99
99
|
const versionMatch = this.version?.match(/^(0\.\d+|\d+)/)
|
|
100
100
|
const versionSimplified = versionMatch?.[1] ?? 'unknown'
|
|
101
101
|
koa.use(async ctx => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IncomingMessage } from 'node:http'
|
|
2
|
+
import { isTruthyHeader } from '../utils/truthyHeader.js'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Opt-in mechanism to coerce the HTTP status of a GraphQL API response to 200.
|
|
@@ -17,16 +18,7 @@ export const forceHttpOkHeader = 'x-contember-force-ok'
|
|
|
17
18
|
|
|
18
19
|
const graphqlModules = new Set(['content', 'tenant', 'system'])
|
|
19
20
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
export const isForceHttpOkRequested = (request: IncomingMessage): boolean => {
|
|
23
|
-
const raw = request.headers[forceHttpOkHeader]
|
|
24
|
-
const value = Array.isArray(raw) ? raw[0] : raw
|
|
25
|
-
if (value === undefined) {
|
|
26
|
-
return false
|
|
27
|
-
}
|
|
28
|
-
return truthyValues.has(value.trim().toLowerCase())
|
|
29
|
-
}
|
|
21
|
+
export const isForceHttpOkRequested = (request: IncomingMessage): boolean => isTruthyHeader(request, forceHttpOkHeader)
|
|
30
22
|
|
|
31
23
|
export const isGraphqlModule = (module: string | undefined): boolean => module !== undefined && graphqlModules.has(module)
|
|
32
24
|
|
|
@@ -183,6 +183,7 @@ export const serverConfigSchema = Typesafe.partial({
|
|
|
183
183
|
}),
|
|
184
184
|
contentApi: Typesafe.partial({
|
|
185
185
|
schemaCacheTtlSeconds: Typesafe.integer,
|
|
186
|
+
forcePrimaryHeader: Typesafe.boolean,
|
|
186
187
|
whereOptimizer: Typesafe.partial({
|
|
187
188
|
disable: Typesafe.boolean,
|
|
188
189
|
maxCrossOptimizationInput: Typesafe.number,
|
|
@@ -218,6 +219,8 @@ export const serverConfigSchema = Typesafe.partial({
|
|
|
218
219
|
monitoringPort: Typesafe.number,
|
|
219
220
|
workerCount: Typesafe.union(Typesafe.number, Typesafe.string),
|
|
220
221
|
applicationWorker: Typesafe.string,
|
|
222
|
+
// How long the engine keeps serving after SIGTERM before it shuts down; unset means at once.
|
|
223
|
+
shutdownDelayMs: Typesafe.number,
|
|
221
224
|
test: Typesafe.partial({
|
|
222
225
|
transactions: Typesafe.boolean,
|
|
223
226
|
transactionTtlSeconds: Typesafe.number,
|
|
@@ -87,6 +87,7 @@ export const configTemplate: any = {
|
|
|
87
87
|
monitoringPort: '%?env.CONTEMBER_MONITORING_PORT::number%',
|
|
88
88
|
workerCount: '%?env.CONTEMBER_WORKER_COUNT::string%',
|
|
89
89
|
applicationWorker: '%?env.CONTEMBER_APPLICATION_WORKER::string%',
|
|
90
|
+
shutdownDelayMs: '%?env.CONTEMBER_SHUTDOWN_DELAY_MS::number%',
|
|
90
91
|
http: {
|
|
91
92
|
requestBodySize: '%?env.CONTEMBER_HTTP_REQUEST_BODY_SIZE::string%',
|
|
92
93
|
suppressAccessLog: '%?env.CONTEMBER_HTTP_SUPPRESS_ACCESS_LOG::string%',
|
|
@@ -100,6 +101,7 @@ export const configTemplate: any = {
|
|
|
100
101
|
},
|
|
101
102
|
contentApi: {
|
|
102
103
|
schemaCacheTtlSeconds: '%?env.CONTEMBER_CONTENT_API_SCHEMA_CACHE_TTL_SECONDS::number%',
|
|
104
|
+
forcePrimaryHeader: '%?env.CONTEMBER_CONTENT_API_FORCE_PRIMARY_HEADER::bool%',
|
|
103
105
|
whereOptimizer: {
|
|
104
106
|
disable: '%?env.CONTEMBER_CONTENT_API_WHERE_OPTIMIZER_DISABLE::bool%',
|
|
105
107
|
maxCrossOptimizationInput: '%?env.CONTEMBER_CONTENT_API_MAX_CROSS_OPTIMIZATION_INPUT::number%',
|
|
@@ -10,9 +10,11 @@ import { ContentQueryHandler, ContentQueryHandlerFactory } from './ContentQueryH
|
|
|
10
10
|
import { GraphQlSchemaFactory } from './GraphQlSchemaFactory.js'
|
|
11
11
|
import { NotModifiedChecker } from './NotModifiedChecker.js'
|
|
12
12
|
import { TestTransactionService } from '../testing/index.js'
|
|
13
|
+
import { isTruthyHeader } from '../utils/truthyHeader.js'
|
|
13
14
|
|
|
14
15
|
const debugHeader = 'x-contember-debug'
|
|
15
16
|
const testSessionHeader = 'x-contember-test-session'
|
|
17
|
+
const forcePrimaryHeader = 'x-contember-force-primary'
|
|
16
18
|
|
|
17
19
|
export class ContentApiControllerFactory {
|
|
18
20
|
constructor(
|
|
@@ -22,6 +24,7 @@ export class ContentApiControllerFactory {
|
|
|
22
24
|
private readonly projectContextResolver: ProjectContextResolver,
|
|
23
25
|
private readonly graphQlSchemaFactory: GraphQlSchemaFactory,
|
|
24
26
|
private readonly testTransactionService: TestTransactionService,
|
|
27
|
+
private readonly forcePrimaryHeaderEnabled: boolean,
|
|
25
28
|
) {
|
|
26
29
|
}
|
|
27
30
|
|
|
@@ -38,7 +41,10 @@ export class ContentApiControllerFactory {
|
|
|
38
41
|
project: project.slug,
|
|
39
42
|
})
|
|
40
43
|
|
|
41
|
-
const
|
|
44
|
+
const forcePrimary = this.forcePrimaryHeaderEnabled && isTruthyHeader(request, forcePrimaryHeader)
|
|
45
|
+
// Without a replica, forced reads change nothing, so clients need not open a window.
|
|
46
|
+
const markMutations = this.forcePrimaryHeaderEnabled && projectContainer.readConnection !== projectContainer.connection
|
|
47
|
+
const systemDatabase = forcePrimary ? projectContainer.systemDatabaseContext : projectContainer.systemReadDatabaseContext
|
|
42
48
|
const stage = await systemDatabase.queryHandler.fetch(new StageBySlugQuery(params.stageSlug))
|
|
43
49
|
if (!stage) {
|
|
44
50
|
return new HttpErrorResponse(404, `Stage ${params.stageSlug} NOT found`)
|
|
@@ -133,11 +139,15 @@ export class ContentApiControllerFactory {
|
|
|
133
139
|
request: koa.request,
|
|
134
140
|
response: koa.response,
|
|
135
141
|
createContext: ({ operation }) => {
|
|
142
|
+
// Clients open a primary read window only on this marker, so it must not be sent while the header is ignored.
|
|
143
|
+
if (operation === 'mutation' && markMutations) {
|
|
144
|
+
koa.response.set('X-Contember-Mutation', '1')
|
|
145
|
+
}
|
|
136
146
|
;(koa.state as GraphQLKoaState).graphql = {
|
|
137
147
|
operationName: operation,
|
|
138
148
|
}
|
|
139
149
|
|
|
140
|
-
const baseConnection = operation === 'query' ? projectContainer.readConnection : projectContainer.connection
|
|
150
|
+
const baseConnection = operation === 'query' && !forcePrimary ? projectContainer.readConnection : projectContainer.connection
|
|
141
151
|
const maxConnectionsPerRequest = 'maxConnectionsPerRequest' in project.db
|
|
142
152
|
? project.db.maxConnectionsPerRequest
|
|
143
153
|
: undefined
|
|
@@ -104,31 +104,35 @@ export class ProjectGroupContainerFactory {
|
|
|
104
104
|
})
|
|
105
105
|
.addService('projectSchemaResolver', () => new ProjectSchemaResolverProxy())
|
|
106
106
|
.addService('projectInitializer', () => new ProjectInitializerProxy())
|
|
107
|
-
.addService(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
.addService(
|
|
108
|
+
'tenantContainer',
|
|
109
|
+
({ tenantConnection, tenantReadConnection, tenantDbCredentials, projectSchemaResolver, projectInitializer, logger }) => {
|
|
110
|
+
const encryptionKey = config.secrets.encryptionKey
|
|
111
|
+
? createSecretKey(Buffer.from(config.secrets.encryptionKey, 'hex'))
|
|
112
|
+
: undefined
|
|
111
113
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
114
|
+
const cryptoWrapper = new CryptoWrapper(encryptionKey)
|
|
115
|
+
return this.tenantContainerFactory.create({
|
|
116
|
+
connection: tenantConnection,
|
|
117
|
+
readConnection: tenantReadConnection,
|
|
118
|
+
dbCredentials: tenantDbCredentials,
|
|
119
|
+
mailOptions: config.mailer,
|
|
120
|
+
tenantCredentials: {
|
|
121
|
+
...config.credentials,
|
|
122
|
+
rootTokens: normalizeTokenList(config.credentials.rootTokens),
|
|
123
|
+
rootTokenHashes: normalizeTokenList(config.credentials.rootTokenHashes),
|
|
124
|
+
},
|
|
125
|
+
projectInitializer,
|
|
126
|
+
projectSchemaResolver,
|
|
127
|
+
logger,
|
|
128
|
+
cryptoProviders: {
|
|
129
|
+
decrypt: cryptoWrapper.decrypt.bind(cryptoWrapper),
|
|
130
|
+
encrypt: cryptoWrapper.encrypt.bind(cryptoWrapper),
|
|
131
|
+
encryptionEnabled: cryptoWrapper.enabled,
|
|
132
|
+
},
|
|
133
|
+
})
|
|
134
|
+
},
|
|
135
|
+
)
|
|
132
136
|
.addService('tenantDatabase', ({ tenantContainer }) => tenantContainer.databaseContext)
|
|
133
137
|
.addService('tenantReadDatabase', ({ tenantContainer }) => tenantContainer.readDatabaseContext)
|
|
134
138
|
.addService('identityFetcher', ({ tenantContainer: { identityFetcher } }) => identityFetcher)
|
|
@@ -7,9 +7,27 @@ const signals = {
|
|
|
7
7
|
SIGTERM: 15,
|
|
8
8
|
}
|
|
9
9
|
export type TerminationJob = (args: { signal: keyof typeof signals; code: number }) => Promise<void>
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
export interface ProcessTerminationOptions {
|
|
12
|
+
/**
|
|
13
|
+
* How long the process keeps serving after SIGTERM before the jobs run. An orchestrator stops routing to
|
|
14
|
+
* a process only some time after signalling it, so draining at once refuses what is still on its way.
|
|
15
|
+
* SIGINT and SIGHUP never wait.
|
|
16
|
+
*/
|
|
17
|
+
readonly sigtermDelayMs?: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const listenOnProcessTermination = (
|
|
21
|
+
jobs: TerminationJob[],
|
|
22
|
+
logger: Logger,
|
|
23
|
+
{ sigtermDelayMs = 0 }: ProcessTerminationOptions = {},
|
|
24
|
+
) => {
|
|
11
25
|
for (const [signal, code] of Object.entries(signals)) {
|
|
12
26
|
process.on(signal, async () => {
|
|
27
|
+
if (signal === 'SIGTERM' && sigtermDelayMs > 0) {
|
|
28
|
+
logger.info(`Process ${process.pid} received a SIGTERM signal, serving for another ${sigtermDelayMs} ms before terminating`)
|
|
29
|
+
await new Promise(resolve => setTimeout(resolve, sigtermDelayMs))
|
|
30
|
+
}
|
|
13
31
|
logger.info(`Process ${process.pid} received a ${signal} signal, executing ${jobs.length} termination jobs`)
|
|
14
32
|
await Promise.allSettled(jobs.map(it => it({ signal: signal as keyof typeof signals, code })))
|
|
15
33
|
logger.info(cluster.isMaster ? `All terminated, exiting` : 'All terminated, exiting a worker')
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IncomingMessage } from 'node:http'
|
|
2
|
+
|
|
3
|
+
const truthyValues = new Set(['1', 'true', 'on', 'yes'])
|
|
4
|
+
|
|
5
|
+
export const isTruthyHeader = (request: IncomingMessage, header: string): boolean => {
|
|
6
|
+
const raw = request.headers[header]
|
|
7
|
+
const value = Array.isArray(raw) ? raw[0] : raw
|
|
8
|
+
if (value === undefined) {
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
return truthyValues.has(value.trim().toLowerCase())
|
|
12
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { expect, spyOn, test } from 'bun:test'
|
|
2
|
+
import { Client as PgClient } from 'pg'
|
|
3
|
+
import Koa from 'koa'
|
|
4
|
+
import { IncomingMessage, ServerResponse } from 'node:http'
|
|
5
|
+
import { Socket } from 'node:net'
|
|
6
|
+
import { GraphQLError, GraphQLObjectType, GraphQLSchema, GraphQLString } from 'graphql'
|
|
7
|
+
import { Connection, emptyDatabaseMetadata, EventManager, Pool } from '@contember/database'
|
|
8
|
+
import { DatabaseContext, DatabaseContextFactory } from '@contember/engine-system-api'
|
|
9
|
+
import { ExecutionContainerFactory } from '@contember/engine-content-api'
|
|
10
|
+
import { emptySchema } from '@contember/schema-utils'
|
|
11
|
+
import { createLogger, TestLoggerHandler } from '@contember/logger'
|
|
12
|
+
import { createMock } from '../../utils.js'
|
|
13
|
+
import { ContentApiControllerFactory } from '../../../src/content/ContentApiControllerFactory.js'
|
|
14
|
+
import { ContentGraphqlContext } from '../../../src/content/ContentGraphqlContext.js'
|
|
15
|
+
import { ContentQueryHandlerFactory } from '../../../src/content/ContentQueryHandlerFactory.js'
|
|
16
|
+
import { ContentSchemaResolver } from '../../../src/content/ContentSchemaResolver.js'
|
|
17
|
+
import { GraphQlSchemaFactory } from '../../../src/content/GraphQlSchemaFactory.js'
|
|
18
|
+
import { NotModifiedChecker } from '../../../src/content/NotModifiedChecker.js'
|
|
19
|
+
import { ProjectMembershipResolver } from '../../../src/content/ProjectMembershipResolver.js'
|
|
20
|
+
import { ProjectContextResolver } from '../../../src/project-common/index.js'
|
|
21
|
+
import { ProjectContainer } from '../../../src/project/ProjectContainer.js'
|
|
22
|
+
import { ProjectDatabaseMetadataResolver } from '../../../src/project/ProjectDatabaseMetadataResolver.js'
|
|
23
|
+
import { ProjectConfig } from '../../../src/project/config.js'
|
|
24
|
+
import { ProjectGroupContainer } from '../../../src/projectGroup/ProjectGroupContainer.js'
|
|
25
|
+
import { TestTransactionService } from '../../../src/testing/index.js'
|
|
26
|
+
import { createProviders } from '../../../src/providers.js'
|
|
27
|
+
import { HttpResponse } from '../../../src/common/index.js'
|
|
28
|
+
|
|
29
|
+
const unavailable = (): never => {
|
|
30
|
+
throw new Error('Unused test dependency')
|
|
31
|
+
}
|
|
32
|
+
const stage = { id: 'a4c9b8f2-6a1e-4a3f-9a4b-1f2e3d4c5b6a', name: 'Live', slug: 'live', schema: 'stage_live' }
|
|
33
|
+
|
|
34
|
+
const createHarness = ({ forcePrimaryHeader = true, withReplica = true }: { forcePrimaryHeader?: boolean; withReplica?: boolean } = {}) => {
|
|
35
|
+
const statements: { side: string; sql: string }[] = []
|
|
36
|
+
const preparation: DatabaseContext[] = []
|
|
37
|
+
let replicaAvailable = true
|
|
38
|
+
const database = (side: 'primary' | 'replica') => {
|
|
39
|
+
const client: ReturnType<ConstructorParameters<typeof Pool>[0]> = new PgClient()
|
|
40
|
+
spyOn(client, 'connect').mockResolvedValue(undefined)
|
|
41
|
+
spyOn(client, 'end').mockResolvedValue(undefined)
|
|
42
|
+
const query = spyOn(client, 'query')
|
|
43
|
+
const events = new EventManager(null)
|
|
44
|
+
events.on(EventManager.Event.queryStart, ({ sql }) => {
|
|
45
|
+
statements.push({ side, sql })
|
|
46
|
+
if (side === 'replica' && !replicaAvailable) {
|
|
47
|
+
query.mockRejectedValueOnce(new Error('Replica unavailable'))
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
const rows = sql.includes('"stage_transaction"')
|
|
51
|
+
? [{ transaction_id: side === 'primary' ? 'new-ref' : 'old-ref' }]
|
|
52
|
+
: sql.includes('"stage"')
|
|
53
|
+
? [stage]
|
|
54
|
+
: [{ marker: side }]
|
|
55
|
+
query.mockResolvedValueOnce({ rows, rowCount: rows.length, command: 'SELECT', oid: 0, fields: [] })
|
|
56
|
+
})
|
|
57
|
+
return new Connection(new Pool(() => client, { maxConnections: 1, logError: () => {} }), events)
|
|
58
|
+
}
|
|
59
|
+
const primary = database('primary')
|
|
60
|
+
const replica = withReplica ? database('replica') : primary
|
|
61
|
+
const providers = createProviders()
|
|
62
|
+
const logger = createLogger(new TestLoggerHandler())
|
|
63
|
+
const systemDatabaseContextFactory = new DatabaseContextFactory('system', providers)
|
|
64
|
+
const project: ProjectConfig = {
|
|
65
|
+
slug: 'test',
|
|
66
|
+
name: 'Test',
|
|
67
|
+
stages: [],
|
|
68
|
+
db: { host: 'primary', port: 5432, user: 'test', password: 'test', database: 'test', read: { host: 'replica' } },
|
|
69
|
+
}
|
|
70
|
+
const projectContainer: ProjectContainer = {
|
|
71
|
+
project,
|
|
72
|
+
logger,
|
|
73
|
+
connection: primary,
|
|
74
|
+
readConnection: replica,
|
|
75
|
+
systemDatabaseContextFactory,
|
|
76
|
+
systemDatabaseContext: systemDatabaseContextFactory.create(primary),
|
|
77
|
+
systemReadDatabaseContext: systemDatabaseContextFactory.create(replica),
|
|
78
|
+
contentSchemaResolver: createMock<ContentSchemaResolver>({
|
|
79
|
+
clearCache: () => {},
|
|
80
|
+
getSchema: async ({ db }) => {
|
|
81
|
+
preparation.push(db)
|
|
82
|
+
return { schema: emptySchema, meta: {} }
|
|
83
|
+
},
|
|
84
|
+
}),
|
|
85
|
+
projectDatabaseMetadataResolver: createMock<ProjectDatabaseMetadataResolver>({
|
|
86
|
+
resolveDatabaseMetadata: async db => {
|
|
87
|
+
preparation.push(db)
|
|
88
|
+
return emptyDatabaseMetadata
|
|
89
|
+
},
|
|
90
|
+
}),
|
|
91
|
+
get projectInitializer() {
|
|
92
|
+
return unavailable()
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
const marker = {
|
|
96
|
+
type: GraphQLString,
|
|
97
|
+
resolve: async (_source: unknown, _args: unknown, context: ContentGraphqlContext) => {
|
|
98
|
+
const result = await context.db.query<{ marker: string }>('SELECT marker')
|
|
99
|
+
return result.rows[0].marker
|
|
100
|
+
},
|
|
101
|
+
}
|
|
102
|
+
const schema = new GraphQLSchema({
|
|
103
|
+
query: new GraphQLObjectType({ name: 'Query', fields: { marker } }),
|
|
104
|
+
mutation: new GraphQLObjectType({
|
|
105
|
+
name: 'Mutation',
|
|
106
|
+
fields: {
|
|
107
|
+
marker,
|
|
108
|
+
fail: {
|
|
109
|
+
type: GraphQLString,
|
|
110
|
+
resolve: () => {
|
|
111
|
+
throw new GraphQLError('Mutation failed')
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
})
|
|
117
|
+
const controller = new ContentApiControllerFactory(
|
|
118
|
+
new NotModifiedChecker(),
|
|
119
|
+
new ExecutionContainerFactory(providers),
|
|
120
|
+
new ContentQueryHandlerFactory(false),
|
|
121
|
+
createMock<ProjectContextResolver>({ resolve: async () => ({ projectContainer, project }) }),
|
|
122
|
+
createMock<GraphQlSchemaFactory>({ create: () => ({ schema, permissions: {}, allPermissions: {} }) }),
|
|
123
|
+
new TestTransactionService(false),
|
|
124
|
+
forcePrimaryHeader,
|
|
125
|
+
).create()
|
|
126
|
+
const projectGroup: ProjectGroupContainer = {
|
|
127
|
+
slug: undefined,
|
|
128
|
+
logger,
|
|
129
|
+
projectMembershipResolver: createMock<ProjectMembershipResolver>({ resolveMemberships: async () => ({ effective: [], fetched: [] }) }),
|
|
130
|
+
get authenticator() {
|
|
131
|
+
return unavailable()
|
|
132
|
+
},
|
|
133
|
+
get projectContainerResolver() {
|
|
134
|
+
return unavailable()
|
|
135
|
+
},
|
|
136
|
+
get projectSchemaResolver() {
|
|
137
|
+
return unavailable()
|
|
138
|
+
},
|
|
139
|
+
get projectInitializer() {
|
|
140
|
+
return unavailable()
|
|
141
|
+
},
|
|
142
|
+
get tenantContainer() {
|
|
143
|
+
return unavailable()
|
|
144
|
+
},
|
|
145
|
+
get tenantGraphQLHandler() {
|
|
146
|
+
return unavailable()
|
|
147
|
+
},
|
|
148
|
+
get systemContainer() {
|
|
149
|
+
return unavailable()
|
|
150
|
+
},
|
|
151
|
+
get systemGraphQLHandler() {
|
|
152
|
+
return unavailable()
|
|
153
|
+
},
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
statements,
|
|
157
|
+
preparation,
|
|
158
|
+
primarySystem: projectContainer.systemDatabaseContext,
|
|
159
|
+
replicaSystem: projectContainer.systemReadDatabaseContext,
|
|
160
|
+
setReplicaUnavailable: () => {
|
|
161
|
+
replicaAvailable = false
|
|
162
|
+
},
|
|
163
|
+
close: async () => {
|
|
164
|
+
await primary.end()
|
|
165
|
+
if (replica !== primary) {
|
|
166
|
+
await replica.end()
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
request: async (query: string, headers: Record<string, string> = {}) => {
|
|
170
|
+
const message = new IncomingMessage(new Socket())
|
|
171
|
+
message.method = 'POST'
|
|
172
|
+
message.url = '/content/test/live'
|
|
173
|
+
message.headers = headers
|
|
174
|
+
const response = new ServerResponse(message)
|
|
175
|
+
const koa = new Koa().createContext(message, response)
|
|
176
|
+
const body = { query }
|
|
177
|
+
Object.assign(koa.request, { body })
|
|
178
|
+
const result = await controller({
|
|
179
|
+
koa,
|
|
180
|
+
body,
|
|
181
|
+
request: message,
|
|
182
|
+
response,
|
|
183
|
+
projectGroup,
|
|
184
|
+
logger,
|
|
185
|
+
url: new URL('http://localhost/content/test/live'),
|
|
186
|
+
clientIp: '127.0.0.1',
|
|
187
|
+
timer: (_event, callback) => callback(),
|
|
188
|
+
requestDebugMode: false,
|
|
189
|
+
authResult: { valid: true, identityId: 'identity', apiKeyId: 'key', roles: [], personId: null, trustForwardedInfo: false },
|
|
190
|
+
params: { projectSlug: 'test', stageSlug: 'live' },
|
|
191
|
+
})
|
|
192
|
+
return { koa, result }
|
|
193
|
+
},
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
test('force-primary routes preparation, cache validation and content to primary even with an unavailable replica', async () => {
|
|
198
|
+
const harness = createHarness()
|
|
199
|
+
try {
|
|
200
|
+
harness.setReplicaUnavailable()
|
|
201
|
+
const { koa, result } = await harness.request('{ marker }', { 'x-contember-force-primary': '1', 'x-contember-ref': 'old-ref' })
|
|
202
|
+
expect(result).toBeUndefined()
|
|
203
|
+
expect(koa.body).toBe('{"data":{"marker":"primary"}}')
|
|
204
|
+
expect(koa.response.get('X-Contember-Mutation')).toBe('')
|
|
205
|
+
expect(harness.statements.every(it => it.side === 'primary')).toBe(true)
|
|
206
|
+
expect(harness.statements.some(it => it.sql.includes('"stage_transaction"'))).toBe(true)
|
|
207
|
+
expect(harness.preparation).toEqual([harness.primarySystem, harness.primarySystem])
|
|
208
|
+
} finally {
|
|
209
|
+
await harness.close()
|
|
210
|
+
}
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
test('a forced primary read can return 304 from the primary reference', async () => {
|
|
214
|
+
const harness = createHarness()
|
|
215
|
+
try {
|
|
216
|
+
const { result } = await harness.request('{ marker }', { 'x-contember-force-primary': '1', 'x-contember-ref': 'new-ref' })
|
|
217
|
+
expect(result).toBeInstanceOf(HttpResponse)
|
|
218
|
+
expect(result instanceof HttpResponse && result.code).toBe(304)
|
|
219
|
+
expect(harness.statements.some(it => it.sql === 'SELECT marker')).toBe(false)
|
|
220
|
+
} finally {
|
|
221
|
+
await harness.close()
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
test('without the header, preparation, cache validation and content read the replica', async () => {
|
|
226
|
+
const harness = createHarness()
|
|
227
|
+
try {
|
|
228
|
+
const { koa } = await harness.request('{ marker }', { 'x-contember-ref': 'new-ref' })
|
|
229
|
+
expect(koa.body).toBe('{"data":{"marker":"replica"}}')
|
|
230
|
+
expect(harness.statements.every(it => it.side === 'replica')).toBe(true)
|
|
231
|
+
expect(harness.statements.some(it => it.sql.includes('"stage_transaction"'))).toBe(true)
|
|
232
|
+
expect(harness.preparation).toEqual([harness.replicaSystem, harness.replicaSystem])
|
|
233
|
+
} finally {
|
|
234
|
+
await harness.close()
|
|
235
|
+
}
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
test('the header accepts the same truthy values as X-Contember-Force-Ok; ordinary queries still read the replica', async () => {
|
|
239
|
+
const harness = createHarness()
|
|
240
|
+
try {
|
|
241
|
+
for (const value of ['1', 'true', ' ON ', 'yes']) {
|
|
242
|
+
const { koa } = await harness.request('{ marker }', { 'x-contember-force-primary': value })
|
|
243
|
+
expect(koa.body).toBe('{"data":{"marker":"primary"}}')
|
|
244
|
+
}
|
|
245
|
+
const headerCases: Record<string, string>[] = [{}, { 'x-contember-force-primary': '0' }, { 'x-contember-force-primary': 'false' }]
|
|
246
|
+
for (const headers of headerCases) {
|
|
247
|
+
const { koa } = await harness.request('{ marker }', headers)
|
|
248
|
+
expect(koa.body).toBe('{"data":{"marker":"replica"}}')
|
|
249
|
+
}
|
|
250
|
+
} finally {
|
|
251
|
+
await harness.close()
|
|
252
|
+
}
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
test('without the config opt-in the header is ignored and mutations are not marked', async () => {
|
|
256
|
+
const harness = createHarness({ forcePrimaryHeader: false })
|
|
257
|
+
try {
|
|
258
|
+
const query = await harness.request('{ marker }', { 'x-contember-force-primary': '1' })
|
|
259
|
+
expect(query.koa.body).toBe('{"data":{"marker":"replica"}}')
|
|
260
|
+
expect(harness.statements.every(it => it.side === 'replica')).toBe(true)
|
|
261
|
+
expect(harness.preparation).toEqual([harness.replicaSystem, harness.replicaSystem])
|
|
262
|
+
const mutation = await harness.request('mutation { marker }')
|
|
263
|
+
expect(mutation.koa.body).toBe('{"data":{"marker":"primary"}}')
|
|
264
|
+
expect(mutation.koa.response.get('X-Contember-Mutation')).toBe('')
|
|
265
|
+
} finally {
|
|
266
|
+
await harness.close()
|
|
267
|
+
}
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
test('mutations run on primary and are marked even when a later root fails', async () => {
|
|
271
|
+
const harness = createHarness()
|
|
272
|
+
try {
|
|
273
|
+
const { koa } = await harness.request('mutation { marker fail }')
|
|
274
|
+
expect(koa.response.get('X-Contember-Mutation')).toBe('1')
|
|
275
|
+
expect(koa.body).toContain('"marker":"primary"')
|
|
276
|
+
expect(koa.body).toContain('Mutation failed')
|
|
277
|
+
const invalid = await harness.request('mutation { unknown }')
|
|
278
|
+
expect(invalid.koa.response.get('X-Contember-Mutation')).toBe('')
|
|
279
|
+
} finally {
|
|
280
|
+
await harness.close()
|
|
281
|
+
}
|
|
282
|
+
})
|
|
283
|
+
|
|
284
|
+
test('a project without a read replica does not mark mutations', async () => {
|
|
285
|
+
const harness = createHarness({ withReplica: false })
|
|
286
|
+
try {
|
|
287
|
+
const { koa } = await harness.request('mutation { marker }')
|
|
288
|
+
expect(koa.body).toBe('{"data":{"marker":"primary"}}')
|
|
289
|
+
expect(koa.response.get('X-Contember-Mutation')).toBe('')
|
|
290
|
+
} finally {
|
|
291
|
+
await harness.close()
|
|
292
|
+
}
|
|
293
|
+
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { expect, test } from 'bun:test'
|
|
2
|
+
import { readConfig } from '../../../src/config/config.js'
|
|
2
3
|
import { serverConfigSchema } from '../../../src/config/configSchema.js'
|
|
3
4
|
|
|
4
5
|
const trustedProxies = (val: unknown): unknown => serverConfigSchema({ http: { trustedProxies: val } }).http?.trustedProxies
|
|
@@ -68,3 +69,18 @@ test('geoCountryHeader: a non-string value throws (fail-fast on misconfiguration
|
|
|
68
69
|
expect(() => geoCountryHeader(123)).toThrow()
|
|
69
70
|
expect(() => geoCountryHeader({})).toThrow()
|
|
70
71
|
})
|
|
72
|
+
|
|
73
|
+
test('shutdownDelayMs: read from CONTEMBER_SHUTDOWN_DELAY_MS', async () => {
|
|
74
|
+
process.env.CONTEMBER_SHUTDOWN_DELAY_MS = '5000'
|
|
75
|
+
try {
|
|
76
|
+
const { serverConfig } = await readConfig()
|
|
77
|
+
expect(serverConfig.shutdownDelayMs).toBe(5000)
|
|
78
|
+
} finally {
|
|
79
|
+
delete process.env.CONTEMBER_SHUTDOWN_DELAY_MS
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test('shutdownDelayMs: undefined when the variable is unset', async () => {
|
|
84
|
+
const { serverConfig } = await readConfig()
|
|
85
|
+
expect(serverConfig.shutdownDelayMs).toBeUndefined()
|
|
86
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createLogger, TestLoggerHandler } from '@contember/logger'
|
|
2
|
+
import { listenOnProcessTermination } from '../../../src/utils/serverTermination.js'
|
|
3
|
+
|
|
4
|
+
// Driven by serverTermination.test.ts: prints READY once it listens for signals, JOBS once the jobs run.
|
|
5
|
+
listenOnProcessTermination(
|
|
6
|
+
[async () => {
|
|
7
|
+
console.log('JOBS')
|
|
8
|
+
}],
|
|
9
|
+
createLogger(new TestLoggerHandler()),
|
|
10
|
+
{ sigtermDelayMs: Number(process.argv[2]) },
|
|
11
|
+
)
|
|
12
|
+
setInterval(() => {}, 60_000)
|
|
13
|
+
console.log('READY')
|