mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
Added protective code to update-check job
refs https://github.com/TryGhost/Ghost/pull/13091 - When the job is run under Node v14 with SQLite DB the parentPort is `null` in some of the environments. The guarding code protects from the job crashing in such situation. - The most probable cause is running btrheds with `BTHREADS_BACKEND = 'child_process';` configuration for SQLite. Should be fixed once https://github.com/mapbox/node-sqlite3/issues/1386 is properly resolved
This commit is contained in:
parent
c6c720634c
commit
7e9c182dc5
@ -1,12 +1,18 @@
|
||||
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() {
|
||||
parentPort.postMessage('Update check job cancelled before completion');
|
||||
postParentPortMessage('Update check job cancelled before completion');
|
||||
|
||||
if (parentPort) {
|
||||
parentPort.postMessage('cancelled');
|
||||
postParentPortMessage('cancelled');
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
process.exit(0);
|
||||
@ -27,13 +33,13 @@ if (parentPort) {
|
||||
|
||||
const logging = {
|
||||
info(message) {
|
||||
parentPort.postMessage(message);
|
||||
postParentPortMessage(message);
|
||||
},
|
||||
warn(message) {
|
||||
parentPort.postMessage(message);
|
||||
postParentPortMessage(message);
|
||||
},
|
||||
error(message) {
|
||||
parentPort.postMessage(message);
|
||||
postParentPortMessage(message);
|
||||
}
|
||||
};
|
||||
|
||||
@ -53,10 +59,10 @@ if (parentPort) {
|
||||
|
||||
await updateCheck({logging});
|
||||
|
||||
parentPort.postMessage(`Ran update check`);
|
||||
postParentPortMessage(`Ran update check`);
|
||||
|
||||
if (parentPort) {
|
||||
parentPort.postMessage('done');
|
||||
postParentPortMessage('done');
|
||||
} else {
|
||||
// give the logging pipes time finish writing before exit
|
||||
setTimeout(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user