From 12a1c60424393dce220cb3ba6a74609cf520426b Mon Sep 17 00:00:00 2001 From: Naz Date: Mon, 22 Feb 2021 19:37:31 +1300 Subject: [PATCH] Added custom worker message handler refs https://github.com/TryGhost/Ghost/issues/12496 - Handling logging in the main thread avoids file handle leaks which happen due to leaky implementation of bunyan logger (see referenced issue for more context) - Bumped job-manager version to allow for `workerMessageHandler` callback funciton --- core/server/services/jobs/job-service.js | 7 ++++++- package.json | 2 +- yarn.lock | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/core/server/services/jobs/job-service.js b/core/server/services/jobs/job-service.js index 562b759a40..12c076510d 100644 --- a/core/server/services/jobs/job-service.js +++ b/core/server/services/jobs/job-service.js @@ -12,6 +12,11 @@ const errorHandler = (error, workerMeta) => { logging.error(error); sentry.captureException(error); }; -const jobManager = new JobManager({logging, errorHandler}); + +const workerMessageHandler = ({name, message}) => { + logging.info(`Worker for job ${name} sent a message: ${message}`); +}; + +const jobManager = new JobManager({logging, errorHandler, workerMessageHandler}); module.exports = jobManager; diff --git a/package.json b/package.json index eb6cd04575..618cf3a0c4 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@tryghost/errors": "0.2.8", "@tryghost/helpers": "1.1.38", "@tryghost/image-transform": "1.0.3", - "@tryghost/job-manager": "0.7.2", + "@tryghost/job-manager": "0.8.0", "@tryghost/kg-card-factory": "2.1.6", "@tryghost/kg-default-atoms": "2.0.3", "@tryghost/kg-default-cards": "4.0.0-rc.6", diff --git a/yarn.lock b/yarn.lock index 9b8ea482e8..e3541b25a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -472,10 +472,10 @@ optionalDependencies: sharp "0.25.4" -"@tryghost/job-manager@0.7.2": - version "0.7.2" - resolved "https://registry.yarnpkg.com/@tryghost/job-manager/-/job-manager-0.7.2.tgz#76db25b81a9039a8d8c4c8389a6c6dc8a86e3326" - integrity sha512-7RalSohNtbjWfUWzQytx0r7seV2bFPeMlRwCAlulNC8pAbpg0Kd0HtayaGeDdpwTVWH4gnn2byIFKhSpLIcvTg== +"@tryghost/job-manager@0.8.0": + version "0.8.0" + resolved "https://registry.yarnpkg.com/@tryghost/job-manager/-/job-manager-0.8.0.tgz#b3e042b7dd6746d8e9e44b71c95d7e2ec75e2881" + integrity sha512-fXgyYaIw0ol99Kr1Nq0DDAH6sbgjIbUxQNsciQPPaUBqfPjdHEhRvrO+PD60nTAM1mZi74BnvCPJwoKAFMy6KA== dependencies: "@breejs/later" "4.0.2" bree "4.1.1"