2021-05-27 17:36:46 +03:00
|
|
|
const {parentPort} = require('bthreads');
|
|
|
|
|
2021-06-29 13:02:16 +03:00
|
|
|
const postParentPortMessage = (message) => {
|
|
|
|
if (parentPort) {
|
|
|
|
parentPort.postMessage(message);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-27 17:36:46 +03:00
|
|
|
// 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() {
|
2021-06-29 13:02:16 +03:00
|
|
|
postParentPortMessage('Update check job cancelled before completion');
|
2021-05-27 17:36:46 +03:00
|
|
|
|
|
|
|
if (parentPort) {
|
2021-06-29 13:02:16 +03:00
|
|
|
postParentPortMessage('cancelled');
|
2021-05-27 17:36:46 +03:00
|
|
|
} 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
|
|
|
|
|
2021-12-06 21:00:55 +03:00
|
|
|
await updateCheck();
|
2021-05-27 17:36:46 +03:00
|
|
|
|
2021-06-29 13:02:16 +03:00
|
|
|
postParentPortMessage(`Ran update check`);
|
2021-05-27 17:36:46 +03:00
|
|
|
|
|
|
|
if (parentPort) {
|
2021-06-29 13:02:16 +03:00
|
|
|
postParentPortMessage('done');
|
2021-05-27 17:36:46 +03:00
|
|
|
} else {
|
|
|
|
// give the logging pipes time finish writing before exit
|
|
|
|
setTimeout(() => {
|
|
|
|
process.exit(0);
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
})();
|