mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 11:54:33 +03:00
Added error rethrow to update check run as a job
closes https://github.com/TryGhost/Toolbox/issues/525 - When the update check is run as an offloaded job (in a worker thread) the errors that are handled over "logger.error" do not get bubbled up to the job manager to be handled fully. With an optional "rethrowErrors" flag it's not possible to throw errors when the update check is run as a "job" and handle as usual when run in the main thread (through the admin route trigger)
This commit is contained in:
parent
17a48c76cd
commit
96a64b4982
@ -42,7 +42,9 @@ if (parentPort) {
|
|||||||
await settings.init();
|
await settings.init();
|
||||||
// Finished INIT
|
// Finished INIT
|
||||||
|
|
||||||
await updateCheck();
|
await updateCheck({
|
||||||
|
rethrowErrors: true
|
||||||
|
});
|
||||||
|
|
||||||
postParentPortMessage(`Ran update check`);
|
postParentPortMessage(`Ran update check`);
|
||||||
|
|
||||||
|
@ -12,10 +12,11 @@ const UpdateCheckService = require('@tryghost/update-check-service');
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes and triggers update check
|
* Initializes and triggers update check
|
||||||
*
|
* @param {Object} [options]
|
||||||
|
* @param {Boolean} [options.rethrowErrors] - if true, errors will be thrown instead of logged
|
||||||
* @returns {Promise<any>}
|
* @returns {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = async () => {
|
module.exports = async ({rethrowErrors = false} = {}) => {
|
||||||
const allowedCheckEnvironments = ['development', 'production'];
|
const allowedCheckEnvironments = ['development', 'production'];
|
||||||
|
|
||||||
// CASE: The check will not happen if your NODE_ENV is not in the allowed defined environments.
|
// CASE: The check will not happen if your NODE_ENV is not in the allowed defined environments.
|
||||||
@ -51,7 +52,8 @@ module.exports = async () => {
|
|||||||
notificationGroups: config.get('notificationGroups'),
|
notificationGroups: config.get('notificationGroups'),
|
||||||
siteUrl: urlUtils.urlFor('home', true),
|
siteUrl: urlUtils.urlFor('home', true),
|
||||||
forceUpdate: config.get('updateCheck:forceUpdate'),
|
forceUpdate: config.get('updateCheck:forceUpdate'),
|
||||||
ghostVersion: ghostVersion.original
|
ghostVersion: ghostVersion.original,
|
||||||
|
rethrowErrors
|
||||||
},
|
},
|
||||||
request,
|
request,
|
||||||
sendEmail: ghostMailer.send.bind(ghostMailer)
|
sendEmail: ghostMailer.send.bind(ghostMailer)
|
||||||
|
@ -45,6 +45,7 @@ class UpdateCheckService {
|
|||||||
* @param {string} options.config.checkEndpoint - update check service URL
|
* @param {string} options.config.checkEndpoint - update check service URL
|
||||||
* @param {boolean} [options.config.isPrivacyDisabled]
|
* @param {boolean} [options.config.isPrivacyDisabled]
|
||||||
* @param {string[]} [options.config.notificationGroups] - example values ["migration", "something"]
|
* @param {string[]} [options.config.notificationGroups] - example values ["migration", "something"]
|
||||||
|
* @param {boolean} [options.config.rethrowErrors] - allows to force throwing errors (useful in worker threads)
|
||||||
* @param {string} options.config.siteUrl - Ghost instance URL
|
* @param {string} options.config.siteUrl - Ghost instance URL
|
||||||
* @param {boolean} [options.config.forceUpdate]
|
* @param {boolean} [options.config.forceUpdate]
|
||||||
* @param {string} options.config.ghostVersion - Ghost instance version
|
* @param {string} options.config.ghostVersion - Ghost instance version
|
||||||
@ -88,6 +89,10 @@ class UpdateCheckService {
|
|||||||
err.help = tpl(messages.checkingForUpdatesFailedHelp, {url: 'https://ghost.org/docs/'});
|
err.help = tpl(messages.checkingForUpdatesFailedHelp, {url: 'https://ghost.org/docs/'});
|
||||||
|
|
||||||
this.logging.error(err);
|
this.logging.error(err);
|
||||||
|
|
||||||
|
if (this.config.rethrowErrors) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -330,7 +335,10 @@ class UpdateCheckService {
|
|||||||
forceTextContent: true
|
forceTextContent: true
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logging.err(err);
|
this.logging.error(err);
|
||||||
|
if (this.config.rethrowErrors) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ require('./utils');
|
|||||||
const sinon = require('sinon');
|
const sinon = require('sinon');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const uuid = require('uuid');
|
const uuid = require('uuid');
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
const logging = require('@tryghost/logging');
|
const logging = require('@tryghost/logging');
|
||||||
const UpdateCheckService = require('../lib/update-check-service');
|
const UpdateCheckService = require('../lib/update-check-service');
|
||||||
@ -371,7 +372,8 @@ describe('Update Check', function () {
|
|||||||
settings: {
|
settings: {
|
||||||
edit: settingsStub
|
edit: settingsStub
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
config: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
updateCheckService.updateCheckError({});
|
updateCheckService.updateCheckError({});
|
||||||
@ -381,5 +383,30 @@ describe('Update Check', function () {
|
|||||||
logging.error.args[0][0].context.should.equal('Checking for updates failed, your site will continue to function.');
|
logging.error.args[0][0].context.should.equal('Checking for updates failed, your site will continue to function.');
|
||||||
logging.error.args[0][0].help.should.equal('If you get this error repeatedly, please seek help from https://ghost.org/docs/');
|
logging.error.args[0][0].help.should.equal('If you get this error repeatedly, please seek help from https://ghost.org/docs/');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('logs and rethrows an error when error with rethrow configuration', function () {
|
||||||
|
const updateCheckService = new UpdateCheckService({
|
||||||
|
api: {
|
||||||
|
settings: {
|
||||||
|
edit: settingsStub
|
||||||
|
}
|
||||||
|
},
|
||||||
|
config: {
|
||||||
|
rethrowErrors: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
updateCheckService.updateCheckError({});
|
||||||
|
assert.fail('should have thrown');
|
||||||
|
} catch (e) {
|
||||||
|
settingsStub.called.should.be.true();
|
||||||
|
logging.error.called.should.be.true();
|
||||||
|
logging.error.args[0][0].context.should.equal('Checking for updates failed, your site will continue to function.');
|
||||||
|
logging.error.args[0][0].help.should.equal('If you get this error repeatedly, please seek help from https://ghost.org/docs/');
|
||||||
|
|
||||||
|
e.context.should.equal('Checking for updates failed, your site will continue to function.');
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user