airbnb / bossbat Goto Github PK
View Code? Open in Web Editor NEWStupid simple distributed job scheduling in node, backed by redis.
License: MIT License
Stupid simple distributed job scheduling in node, backed by redis.
License: MIT License
Interval formats are a little weird. I feel like we should support more duration formats, and also maybe just numbers to represent raw ms
delays.
The timestring
module seems nice.
In addition to the every
key (which is a string or ms value), we should support a new cron
value on the JobDefinition that can be any cron value. We'll parse it and schedule based on it.
This should help support a wider variety of scheduled jobbing outside of just scheduled intervals.
Cron worker runs multiple times during one second with every minute expression.
The following piece of code demonstrates the issue:
const Bossbat = require('bossbat');
const bossbat = new Bossbat();
let i = 0;
bossbat.hire('work', {
cron: '*/1 * * * *',
work: () => {
console.log('Working...', new Date().toString(), i);
i++;
}
});
Output:
Working... Sun Feb 26 2017 14:30:00 GMT+0200 (EET) 0
Working... Sun Feb 26 2017 14:30:00 GMT+0200 (EET) 1
Working... Sun Feb 26 2017 14:30:00 GMT+0200 (EET) 2
Working... Sun Feb 26 2017 14:30:00 GMT+0200 (EET) 3
Working... Sun Feb 26 2017 14:30:00 GMT+0200 (EET) 4
Working... Sun Feb 26 2017 14:30:00 GMT+0200 (EET) 5
Working... Sun Feb 26 2017 14:30:00 GMT+0200 (EET) 6
Working... Sun Feb 26 2017 14:30:00 GMT+0200 (EET) 7
Working... Sun Feb 26 2017 14:30:00 GMT+0200 (EET) 8
Working... Sun Feb 26 2017 14:30:00 GMT+0200 (EET) 9
Working... Sun Feb 26 2017 14:30:01 GMT+0200 (EET) 10
Working... Sun Feb 26 2017 14:31:00 GMT+0200 (EET) 11
Working... Sun Feb 26 2017 14:31:00 GMT+0200 (EET) 12
Working... Sun Feb 26 2017 14:31:00 GMT+0200 (EET) 13
Working... Sun Feb 26 2017 14:31:00 GMT+0200 (EET) 14
Working... Sun Feb 26 2017 14:31:00 GMT+0200 (EET) 15
Working... Sun Feb 26 2017 14:31:00 GMT+0200 (EET) 16
Working... Sun Feb 26 2017 14:31:00 GMT+0200 (EET) 17
Working... Sun Feb 26 2017 14:31:00 GMT+0200 (EET) 18
Working... Sun Feb 26 2017 14:31:00 GMT+0200 (EET) 19
Working... Sun Feb 26 2017 14:31:00 GMT+0200 (EET) 20
Working... Sun Feb 26 2017 14:31:01 GMT+0200 (EET) 21
Expected output:
Working... Sun Feb 26 2017 14:30:00 GMT+0200 (EET) 0
Working... Sun Feb 26 2017 14:31:00 GMT+0200 (EET) 1
The issue occurs only if the runner completes relatively fast (in a couple of milliseconds).
Right now we use some lame split logic that prevents us from using :
in job names. Let's fix that so that we can use whatever name we like. We'll need to ensure the logic works for demands as well as scheduled jobs.
I would like have a bunch of worker machines and one main server that dispatches the job to the workers, but from the source code I don't see how to do it. Is that possible?
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.