bossbat icon indicating copy to clipboard operation
bossbat copied to clipboard

If `work()` resolves too quickly, multiple machines execute at the same time.

Open WeeJeWel opened this issue 1 year ago • 0 comments

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.

WeeJeWel avatar Jan 23 '24 13:01 WeeJeWel