From 3a959c31d0cb8e5770f8e31a990e1475a5cb98e4 Mon Sep 17 00:00:00 2001 From: jen Date: Thu, 23 Nov 2023 16:53:19 +0000 Subject: [PATCH 1/3] wrap prisma connection to prevent possibly unnecessary errors. add queue env vars to buildConfig. --- runner/src/server/prismaClient.ts | 43 +++++++++++++------------ runner/src/server/utils/configSchema.ts | 18 +++++++++++ 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/runner/src/server/prismaClient.ts b/runner/src/server/prismaClient.ts index f8ece3aaeb..acf3a1c84f 100644 --- a/runner/src/server/prismaClient.ts +++ b/runner/src/server/prismaClient.ts @@ -33,32 +33,35 @@ export const prisma: PrismaClient = new PrismaClient({ log: logLevel, }); -prisma.$connect().catch((error) => { - prismaLogger.error(`Prisma Connect Error ${error.message}`); -}); +if (config.enableQueueService) { + prismaLogger.info("ENABLE_QUEUE_SERVICE is true, connecting to Prisma"); + prisma.$connect().catch((error) => { + prismaLogger.error(`Prisma Connect Error ${error.message}`); + }); -process.on("query", (e: Prisma.QueryEvent) => { - if (!config.isTest) { - prismaLogger.info(` + process.on("query", (e: Prisma.QueryEvent) => { + if (!config.isTest) { + prismaLogger.info(` Prisma Query: ${e.query} \r\n Duration: ${e.duration}ms \r\n Params: ${e.params} `); - } -}); + } + }); -process.on("warn", (e) => { - prismaLogger.warn(e); -}); + process.on("warn", (e) => { + prismaLogger.warn(e); + }); -process.on("info", (e) => { - prismaLogger.info(e); -}); + process.on("info", (e) => { + prismaLogger.info(e); + }); -process.on("error", (e) => { - prismaLogger.error(e); -}); + process.on("error", (e) => { + prismaLogger.error(e); + }); -process.on("beforeExit", () => { - prismaLogger.info("Prisma is exiting"); -}); + process.on("beforeExit", () => { + prismaLogger.info("Prisma is exiting"); + }); +} diff --git a/runner/src/server/utils/configSchema.ts b/runner/src/server/utils/configSchema.ts index e9590e7c74..acc3c576a8 100644 --- a/runner/src/server/utils/configSchema.ts +++ b/runner/src/server/utils/configSchema.ts @@ -101,6 +101,24 @@ export const configSchema = Joi.object({ "HS512" ) .default("HS512"), + + enableQueueService: Joi.boolean().optional(), + queueDatabaseUrl: Joi.string().when("enableQueueService", { + then: Joi.required(), + otherwise: Joi.optional(), + }), + queueDatabaseUsername: Joi.string().when("enableQueueService", { + then: Joi.required(), + otherwise: Joi.optional(), + }), + queueDatabasePassword: Joi.string().when("enableQueueService", { + then: Joi.required(), + otherwise: Joi.optional(), + }), + queueServicePollingInterval: Joi.number().when("enableQueueService", { + then: Joi.required(), + otherwise: Joi.optional(), + }), }); export function buildConfig(config) { From d95c8b3bff98e76d7d4658dc469cc5018afdd95d Mon Sep 17 00:00:00 2001 From: jen Date: Thu, 23 Nov 2023 17:29:21 +0000 Subject: [PATCH 2/3] fix: force runner to quit if queue is enabled but could not connect to db --- runner/config/default.js | 5 ++--- runner/config/development.json | 4 +--- runner/src/server/prismaClient.ts | 5 ++++- runner/src/server/utils/configSchema.ts | 12 +++--------- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/runner/config/default.js b/runner/config/default.js index 93684e8406..211d6a7bbd 100644 --- a/runner/config/default.js +++ b/runner/config/default.js @@ -37,7 +37,7 @@ module.exports = { return this.env === "test"; }), isSandbox: deferConfig(function () { - return this.sandbox === true || this.sandbox === "true"; + return evalBooleanEnvVar(this.sandbox); }), /** @@ -133,7 +133,6 @@ module.exports = { * Failure queue */ enableQueueService: false, - queueDatabaseUrl: "", - queueDatabasePassword: "", + // queueDatabaseUrl: "mysql://root:root@localhost:3306/queue" queueServicePollingInterval: "500", }; diff --git a/runner/config/development.json b/runner/config/development.json index 3188e76393..be126c8611 100644 --- a/runner/config/development.json +++ b/runner/config/development.json @@ -2,7 +2,5 @@ "isTest": true, "previewMode": true, "enforceCsrf": false, - "env": "development", - "enableQueueService": true, - "queueDatabaseUrl": "mysql://root:root@localhost:3306/queue" + "env": "development" } diff --git a/runner/src/server/prismaClient.ts b/runner/src/server/prismaClient.ts index acf3a1c84f..1863e5b6c3 100644 --- a/runner/src/server/prismaClient.ts +++ b/runner/src/server/prismaClient.ts @@ -36,7 +36,10 @@ export const prisma: PrismaClient = new PrismaClient({ if (config.enableQueueService) { prismaLogger.info("ENABLE_QUEUE_SERVICE is true, connecting to Prisma"); prisma.$connect().catch((error) => { - prismaLogger.error(`Prisma Connect Error ${error.message}`); + prismaLogger.fatal( + `ENABLE_QUEUE_SERVICE is set to true, but Prisma failed to connect ${error}, exiting with status 1` + ); + process.exit(1); }); process.on("query", (e: Prisma.QueryEvent) => { diff --git a/runner/src/server/utils/configSchema.ts b/runner/src/server/utils/configSchema.ts index acc3c576a8..99e78b0b8b 100644 --- a/runner/src/server/utils/configSchema.ts +++ b/runner/src/server/utils/configSchema.ts @@ -104,18 +104,12 @@ export const configSchema = Joi.object({ enableQueueService: Joi.boolean().optional(), queueDatabaseUrl: Joi.string().when("enableQueueService", { + is: true, then: Joi.required(), - otherwise: Joi.optional(), - }), - queueDatabaseUsername: Joi.string().when("enableQueueService", { - then: Joi.required(), - otherwise: Joi.optional(), - }), - queueDatabasePassword: Joi.string().when("enableQueueService", { - then: Joi.required(), - otherwise: Joi.optional(), + otherwise: Joi.optional().allow(""), }), queueServicePollingInterval: Joi.number().when("enableQueueService", { + is: true, then: Joi.required(), otherwise: Joi.optional(), }), From 7d8ffc4ad06237bebbd16be0dfc8363efaa329cf Mon Sep 17 00:00:00 2001 From: jen Date: Thu, 23 Nov 2023 17:36:08 +0000 Subject: [PATCH 3/3] revert --- runner/config/default.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner/config/default.js b/runner/config/default.js index 211d6a7bbd..b2944f764a 100644 --- a/runner/config/default.js +++ b/runner/config/default.js @@ -37,7 +37,7 @@ module.exports = { return this.env === "test"; }), isSandbox: deferConfig(function () { - return evalBooleanEnvVar(this.sandbox); + return this.sandbox === true || this.sandbox === "true"; }), /**