0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00
ghost/core/server/run-update-check.js
Hannah Wolfe 54b4a3c351
Renamed settings index.js to settings-service.js
- in line with our policy of not keeping logic in index.js files
- Note: callign all services service.js is no more helpful :D
2022-05-10 20:55:31 +01:00

57 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/settings-service');
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);
}
})();