🐛 delay worker thread start

This commit is contained in:
Flam3rboy 2021-10-22 23:42:00 +02:00
parent 90ece05efc
commit 7f51408e0e

View File

@ -61,8 +61,12 @@ Current commit: ${
// Fork workers. // Fork workers.
for (let i = 0; i < cores; i++) { for (let i = 0; i < cores; i++) {
cluster.fork(); // Delay each worker start if using sqlite database to prevent locking it
console.log(`[Process] worker ${i} started.`); let delay = process.env.DATABASE?.includes("://") ? 0 : i * 1000;
setTimeout(() => {
cluster.fork();
console.log(`[Process] worker ${i} started.`);
}, delay);
} }
cluster.on("message", (sender: Worker, message: any) => { cluster.on("message", (sender: Worker, message: any) => {