mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Added central error handler to job manager
refs https://github.com/TryGhost/Ghost-Utils/issues/118 - Duplicating error handling across jobs is not best developer experience. Also, having custom error handling logic did not allow for recommended worker script behavior: allowing for unhandled exceptions to bubble up and be managed by parent process
This commit is contained in:
parent
8aa55feaf8
commit
c1e3788570
5 changed files with 61 additions and 77 deletions
|
@ -1,6 +1,5 @@
|
||||||
const logging = require('../../../../shared/logging');
|
const logging = require('../../../../shared/logging');
|
||||||
const {parentPort} = require('bthreads');
|
const {parentPort} = require('bthreads');
|
||||||
const sentry = require('../../../../shared/sentry');
|
|
||||||
const debug = require('ghost-ignition').debug('jobs:email-analytics:fetch-all');
|
const debug = require('ghost-ignition').debug('jobs:email-analytics:fetch-all');
|
||||||
|
|
||||||
// one-off job to fetch all available events and re-process them idempotently
|
// one-off job to fetch all available events and re-process them idempotently
|
||||||
|
@ -27,7 +26,6 @@ if (parentPort) {
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
|
||||||
const models = require('../../../models');
|
const models = require('../../../models');
|
||||||
const settingsService = require('../../settings');
|
const settingsService = require('../../settings');
|
||||||
|
|
||||||
|
@ -50,7 +48,7 @@ if (parentPort) {
|
||||||
const aggregateEndDate = new Date();
|
const aggregateEndDate = new Date();
|
||||||
debug(`Finished aggregating email analytics in ${aggregateEndDate - aggregateStartDate}ms`);
|
debug(`Finished aggregating email analytics in ${aggregateEndDate - aggregateStartDate}ms`);
|
||||||
|
|
||||||
logging.info(`Fetched ${eventStats.totalEvents} events and aggregated stats for ${eventStats.emailIds.length} emails and ${eventStats.memberIds.length} members in ${aggregateEndDate - fetchStartDate}ms`);
|
logging.info(`Fetched ${eventStats.totalEvents} events and aggregated stats for ${eventStats.emailIds.length} emails in ${aggregateEndDate - fetchStartDate}ms`);
|
||||||
|
|
||||||
if (parentPort) {
|
if (parentPort) {
|
||||||
parentPort.postMessage('done');
|
parentPort.postMessage('done');
|
||||||
|
@ -60,13 +58,4 @@ if (parentPort) {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
logging.error(error);
|
|
||||||
sentry.captureException(error);
|
|
||||||
|
|
||||||
// give the logging pipes time finish writing before exit
|
|
||||||
setTimeout(() => {
|
|
||||||
process.exit(1);
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
const logging = require('../../../../shared/logging');
|
const logging = require('../../../../shared/logging');
|
||||||
const {parentPort} = require('bthreads');
|
const {parentPort} = require('bthreads');
|
||||||
const sentry = require('../../../../shared/sentry');
|
|
||||||
const debug = require('ghost-ignition').debug('jobs:email-analytics:fetch-latest');
|
const debug = require('ghost-ignition').debug('jobs:email-analytics:fetch-latest');
|
||||||
|
|
||||||
// recurring job to fetch analytics since the most recently seen event timestamp
|
// recurring job to fetch analytics since the most recently seen event timestamp
|
||||||
|
@ -28,7 +27,6 @@ if (parentPort) {
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
|
||||||
const models = require('../../../models');
|
const models = require('../../../models');
|
||||||
const settingsService = require('../../settings');
|
const settingsService = require('../../settings');
|
||||||
|
|
||||||
|
@ -51,7 +49,7 @@ if (parentPort) {
|
||||||
const aggregateEndDate = new Date();
|
const aggregateEndDate = new Date();
|
||||||
debug(`Finished aggregating email analytics in ${aggregateEndDate - aggregateStartDate}ms`);
|
debug(`Finished aggregating email analytics in ${aggregateEndDate - aggregateStartDate}ms`);
|
||||||
|
|
||||||
logging.info(`Fetched ${eventStats.totalEvents} events and aggregated stats for ${eventStats.emailIds.length} emails and ${eventStats.memberIds.length} members in ${aggregateEndDate - fetchStartDate}ms`);
|
logging.info(`Fetched ${eventStats.totalEvents} events and aggregated stats for ${eventStats.emailIds.length} emails in ${aggregateEndDate - fetchStartDate}ms`);
|
||||||
|
|
||||||
if (parentPort) {
|
if (parentPort) {
|
||||||
parentPort.postMessage('done');
|
parentPort.postMessage('done');
|
||||||
|
@ -61,13 +59,4 @@ if (parentPort) {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
logging.error(error);
|
|
||||||
sentry.captureException(error);
|
|
||||||
|
|
||||||
// give the logging pipes time finish writing before exit
|
|
||||||
setTimeout(() => {
|
|
||||||
process.exit(1);
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -5,7 +5,13 @@
|
||||||
|
|
||||||
const JobManager = require('@tryghost/job-manager');
|
const JobManager = require('@tryghost/job-manager');
|
||||||
const logging = require('../../../shared/logging');
|
const logging = require('../../../shared/logging');
|
||||||
|
const sentry = require('../../../shared/sentry');
|
||||||
|
|
||||||
const jobManager = new JobManager(logging);
|
const errorHandler = (error, workerMeta) => {
|
||||||
|
logging.info(`Capturing error for worker during execution of job: ${workerMeta.name}`);
|
||||||
|
logging.error(error);
|
||||||
|
sentry.captureException(error);
|
||||||
|
};
|
||||||
|
const jobManager = new JobManager({logging, errorHandler});
|
||||||
|
|
||||||
module.exports = jobManager;
|
module.exports = jobManager;
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
"@tryghost/errors": "0.2.5",
|
"@tryghost/errors": "0.2.5",
|
||||||
"@tryghost/helpers": "1.1.35",
|
"@tryghost/helpers": "1.1.35",
|
||||||
"@tryghost/image-transform": "1.0.3",
|
"@tryghost/image-transform": "1.0.3",
|
||||||
"@tryghost/job-manager": "0.5.0",
|
"@tryghost/job-manager": "0.6.0",
|
||||||
"@tryghost/kg-card-factory": "2.1.4",
|
"@tryghost/kg-card-factory": "2.1.4",
|
||||||
"@tryghost/kg-default-atoms": "2.0.2",
|
"@tryghost/kg-default-atoms": "2.0.2",
|
||||||
"@tryghost/kg-default-cards": "3.0.1",
|
"@tryghost/kg-default-cards": "3.0.1",
|
||||||
|
|
18
yarn.lock
18
yarn.lock
|
@ -381,13 +381,13 @@
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
sharp "0.25.4"
|
sharp "0.25.4"
|
||||||
|
|
||||||
"@tryghost/job-manager@0.5.0":
|
"@tryghost/job-manager@0.6.0":
|
||||||
version "0.5.0"
|
version "0.6.0"
|
||||||
resolved "https://registry.yarnpkg.com/@tryghost/job-manager/-/job-manager-0.5.0.tgz#94ea766503d2473835d10e5e75cbf9cf09d9cccf"
|
resolved "https://registry.yarnpkg.com/@tryghost/job-manager/-/job-manager-0.6.0.tgz#5023f4b37577ac6966bba3608896948f2d030004"
|
||||||
integrity sha512-BhVV0PgCL/Upd6fdcNQMYXzM7KAXcBhTOqsLuhJxaolf9lgWWBZOO575IGST9ezFU8xwidOF2Yecgem1ddpBQQ==
|
integrity sha512-kZh3sAexCkP4WghIskB6ZAJQap8KQWDtcLWRXTzCL1fO6BzOstJgw4gvRMDb2t8peUHhwf34fKbeIKecl5cv0g==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@breejs/later" "4.0.2"
|
"@breejs/later" "4.0.2"
|
||||||
bree "4.0.0"
|
bree "4.1.0"
|
||||||
cron-validate "1.4.1"
|
cron-validate "1.4.1"
|
||||||
fastq "1.9.0"
|
fastq "1.9.0"
|
||||||
p-wait-for "3.1.0"
|
p-wait-for "3.1.0"
|
||||||
|
@ -1328,10 +1328,10 @@ braces@~3.0.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
fill-range "^7.0.1"
|
fill-range "^7.0.1"
|
||||||
|
|
||||||
bree@4.0.0:
|
bree@4.1.0:
|
||||||
version "4.0.0"
|
version "4.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/bree/-/bree-4.0.0.tgz#1ce6b74cbbfd49fb87c171001f37ddcec1cea996"
|
resolved "https://registry.yarnpkg.com/bree/-/bree-4.1.0.tgz#c27c942d6d32fd2ac4809a2a80509298a31fca3e"
|
||||||
integrity sha512-z9vM8rc4KNEzn8j+XOcJDt65ah2G/zuXkEeR2ovzX9A3kaoOL/jo41YLwdTZQ542YBOHcHomzd5pc6CkHAADgQ==
|
integrity sha512-4mQMvYGrTtVp6apa/t4bXMcug7q0Eb6cXgWbly7OdhECT9PFsjyaGrSGr2+2TWUD2TFVEeZEtkk1rl8oGcjvgQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/runtime" "^7.12.5"
|
"@babel/runtime" "^7.12.5"
|
||||||
"@breejs/later" "^4.0.2"
|
"@breejs/later" "^4.0.2"
|
||||||
|
|
Loading…
Add table
Reference in a new issue