Ghost/core/server/run-update-check.js
Sam Lord 97451a93cb
Extract logging from DI patterns, only use @tryghost/logging package
refs: https://github.com/TryGhost/Toolbox/issues/146

Switched to @tryghost/logging instead of passing around the library. The main sticking points of this change are jobs. When jobs are launched we don't want them to use a separate @tryghost/logging instance because they would start parallel rotation jobs. @tryghost/logging v2.x passes all logs to the parent process if run in a child process, so that we can use the same patterns in jobs and the rest of the codebase.
2021-12-06 18:00:55 +00:00

58 lines
1.4 KiB
JavaScript

const {parentPort} = require('bthreads');
const postParentPortMessage = (message) => {
if (parentPort) {
parentPort.postMessage(message);
}
};
// Exit early when cancelled to prevent stalling shutdown. No cleanup needed when cancelling as everything is idempotent and will pick up
// where it left off on next run
function cancel() {
postParentPortMessage('Update check job cancelled before completion');
if (parentPort) {
postParentPortMessage('cancelled');
} else {
setTimeout(() => {
process.exit(0);
}, 1000);
}
}
if (parentPort) {
parentPort.once('message', (message) => {
if (message === 'cancel') {
return cancel();
}
});
}
(async () => {
const updateCheck = require('./update-check');
// INIT required services
const models = require('./models');
models.init();
const permissions = require('./services/permissions');
await permissions.init();
const settings = require('./services/settings');
await settings.init();
// Finished INIT
await updateCheck();
postParentPortMessage(`Ran update check`);
if (parentPort) {
postParentPortMessage('done');
} else {
// give the logging pipes time finish writing before exit
setTimeout(() => {
process.exit(0);
}, 1000);
}
})();