bossbat
bossbat copied to clipboard
If `work()` resolves too quickly, multiple machines execute at the same time.
Consider this code:
this.bossbat.hire('cronjob', {
every: '1 seconds',
work: async () => {
console.log(new Date(), 'Cronjob fired');
await new Promise(resolve => setTimeout(resolve, 1000)); // This is a workaround that fixes this
},
});
If the 'await new Promise' wasn't there, multiple machines would execute the same command because the lock was already released before the other server tried to get it.