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');
|
|
|
|
|
|
|
|
const logging = {
|
|
|
|
info(message) {
|
2021-06-29 13:02:16 +03:00
|
|
|
postParentPortMessage(message);
|
2021-05-27 17:36:46 +03:00
|
|
|
},
|
|
|
|
warn(message) {
|
2021-06-29 13:02:16 +03:00
|
|
|
postParentPortMessage(message);
|
2021-05-27 17:36:46 +03:00
|
|
|
},
|
|
|
|
error(message) {
|
2021-06-29 13:02:16 +03:00
|
|
|
postParentPortMessage(message);
|
2021-05-27 17:36:46 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
const i18n = require('../shared/i18n');
|
|
|
|
i18n.init();
|
|
|
|
// Finished INIT
|
|
|
|
|
|
|
|
await updateCheck({logging});
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
})();
|