Skip to content

Commit a8ffb0f

Browse files
committed
📦 v2.4.0
- 📦 NPM: v2.4.0 - 📦 Meteor: v2.6.0 __Critical Changes__: - `opts.minRevolvingDelay` by default `128` ms, *was 32*; - `opts.maxRevolvingDelay` by default `768` ms, *was 256*; - Default `{ writeConcern }` options removed from write/update operations, pass recommended `readConcern`, `writeConcern`, and `readPreference` as mongodb connections settings; - Implement "Collection Locking" via special collection ending with `.lock` prefix; - In total this package will add two new MongoDB collections per each `new JoSk({ prefix })` to a database it's connected. __Changes__: - 🤝 Compatibility with `[email protected]` (*node native driver*); - 🤝 Compatibility with `meteor@2.*`; - 👨‍💻 Refactor logic and reduce read/write operations; - 👷 Stable distictive runs avoiding simultaneous execution across complex multi-server infrastructure; - 📋 Documentation update.
1 parent 61f08c0 commit a8ffb0f

File tree

5 files changed

+2145
-557
lines changed

5 files changed

+2145
-557
lines changed

.versions

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
2-
babel-compiler@7.5.3
2+
babel-compiler@7.6.0
33
44
55
@@ -9,12 +9,12 @@ [email protected]
99
1010
1111
12-
ddp-client@2.3.3
12+
ddp-client@2.4.0
1313
1414
1515
16-
dynamic-import@0.5.2
17-
ecmascript@0.14.3
16+
dynamic-import@0.6.0
17+
ecmascript@0.15.0
1818
1919
2020
@@ -25,33 +25,34 @@ [email protected]
2525
2626
2727
28-
local-test:ostrio:cron-jobs@2.5.0
29-
logging@1.1.20
28+
local-test:ostrio:cron-jobs@2.6.0
29+
logging@1.2.0
3030
3131
meteorhacks:[email protected]
3232
meteortesting:[email protected]
3333
meteortesting:[email protected]
3434
meteortesting:[email protected]
35-
35+
3636
37-
modules@0.15.0
37+
modules@0.16.0
3838
39-
40-
39+
40+
4141
4242
4343
4444
45-
ostrio:cron-jobs@2.5.0
45+
ostrio:cron-jobs@2.6.0
4646
practicalmeteor:[email protected]_1
4747
4848
49-
49+
50+
5051
5152
5253
5354
5455
5556
56-
webapp@1.9.1
57-
webapp-hashing@1.0.9
57+
webapp@1.10.0
58+
webapp-hashing@1.1.0

README.md

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,24 @@ __This is a server-only package.__
1414

1515
## ToC:
1616

17-
- [Install](https://github.com/VeliovGroup/josk#install) as [NPM package](https://www.npmjs.com/package/josk)
18-
- [Install Meteor](https://github.com/VeliovGroup/josk#install-meteor) as [Atmosphere package](https://atmospherejs.com/ostrio/cron-jobs)
19-
- [API](https://github.com/VeliovGroup/josk#api)
20-
- [Constructor `new JoSk()`](https://github.com/VeliovGroup/josk#initialization)
21-
- [`JoSk#setInterval()`](https://github.com/VeliovGroup/josk#setintervalfunc-delay-uid)
22-
- [`JoSk#setTimeout()`](https://github.com/VeliovGroup/josk#settimeoutfunc-delay-uid)
23-
- [`JoSk#setImmediate()`](https://github.com/VeliovGroup/josk#setimmediatefunc-uid)
24-
- [`JoSk#clearInterval()`](https://github.com/VeliovGroup/josk#clearintervaltimer)
25-
- [`JoSk#clearTimeout()`](https://github.com/VeliovGroup/josk#cleartimeouttimer)
26-
- [`JoSk#destroy()`](https://github.com/VeliovGroup/josk#destroy)
27-
- [~90% tests coverage](https://github.com/VeliovGroup/josk#running-tests)
17+
- [Install](https://github.com/veliovgroup/josk#install) as [NPM package](https://www.npmjs.com/package/josk)
18+
- [Install Meteor](https://github.com/veliovgroup/josk#install-meteor) as [Atmosphere package](https://atmospherejs.com/ostrio/cron-jobs)
19+
- [API](https://github.com/veliovgroup/josk#api)
20+
- [Constructor `new JoSk()`](https://github.com/veliovgroup/josk#initialization)
21+
- [`JoSk#setInterval()`](https://github.com/veliovgroup/josk#setintervalfunc-delay-uid)
22+
- [`JoSk#setTimeout()`](https://github.com/veliovgroup/josk#settimeoutfunc-delay-uid)
23+
- [`JoSk#setImmediate()`](https://github.com/veliovgroup/josk#setimmediatefunc-uid)
24+
- [`JoSk#clearInterval()`](https://github.com/veliovgroup/josk#clearintervaltimer)
25+
- [`JoSk#clearTimeout()`](https://github.com/veliovgroup/josk#cleartimeouttimer)
26+
- [`JoSk#destroy()`](https://github.com/veliovgroup/josk#destroy)
27+
- [~90% tests coverage](https://github.com/veliovgroup/josk#running-tests)
2828

2929
## Main features:
3030

3131
- 👨‍🔬 ~90% tests coverage;
3232
- 📦 Zero dependencies, written from scratch for top performance;
3333
- 🏢 Synchronize single task across multiple servers;
34+
- 🔏 Collection locking to avoid simultaneous task executions across complex infrastructure;
3435
- 💪 Bulletproof design, built-in retries, and "zombie" task recovery 🧟🔫.
3536

3637
## Install:
@@ -87,11 +88,13 @@ job.setInterval(task, 60 * 60 * 1000, 'task');
8788

8889
## Notes:
8990

90-
- This package is perfect when you have multiple servers for load-balancing, durability, an array of micro-services or any other solution with multiple running copies of code when you need to run repeating tasks, and you need to run it only once per app, not per server.
91-
- Limitation — task must be run not often than once per two seconds (from 2 to ∞ seconds). Example tasks: Email, SMS queue, Long-polling requests, Periodical application logic operations or Periodical data fetch and etc.
92-
- Accuracy — Delay of each task depends on MongoDB and "de-synchronization delay". Trusted time-range of execution period is `task_delay ± (256 + MongoDB_Connection_And_Request_Delay)`. That means this package won't fit when you need to run a task with very certain delays. For other cases, if `±256 ms` delays are acceptable - this package is the great solution.
93-
- Use `opts.minRevolvingDelay` and `opts.maxRevolvingDelay` to set the range for *random* delays between executions. Revolving range acts as a safety control to make sure different servers __not__ picking the same task at the same time. Default values (`32` and `256`) are the best for 3-server setup (*the most common topology*). Tune these options to match needs of your project. Higher `opts.minRevolvingDelay` will reduce load on MongoDB.
94-
- To avoid "DB locks" — it's recommended to use separate DB from "main" application DB (*same MongoDB server can have multiple DBs*)
91+
- This package is perfect when you have multiple servers for load-balancing, durability, an array of micro-services or any other solution with multiple running copies of code when you need to run repeating tasks, and you need to run it only once per app, not per server;
92+
- Limitation — task must be run not often than once per two seconds (from 2 to ∞ seconds). Example tasks: Email, SMS queue, Long-polling requests, Periodical application logic operations or Periodical data fetch and etc;
93+
- Accuracy — Delay of each task depends on MongoDB and "de-synchronization delay". Trusted time-range of execution period is `task_delay ± (256 + MongoDB_Connection_And_Request_Delay)`. That means this package won't fit when you need to run a task with very certain delays. For other cases, if `±256 ms` delays are acceptable - this package is the great solution;
94+
- Use `opts.minRevolvingDelay` and `opts.maxRevolvingDelay` to set the range for *random* delays between executions. Revolving range acts as a safety control to make sure different servers __not__ picking the same task at the same time. Default values (`128` and `768`) are the best for 3-server setup (*the most common topology*). Tune these options to match needs of your project. Higher `opts.minRevolvingDelay` will reduce load on MongoDB;
95+
- To avoid "DB locks" — it's recommended to use separate DB from "main" application DB (*same MongoDB server can have multiple DBs*).
96+
- This package implements "Collection Locking" via special collection ending with `.lock` prefix;
97+
- In total this package will add two new MongoDB collections per each `new JoSk({ prefix })` to a database it's connected.
9598

9699
## API:
97100

@@ -102,8 +105,8 @@ job.setInterval(task, 60 * 60 * 1000, 'task');
102105
- `opts.autoClear` {*Boolean*} - [Optional] Remove (*Clear*) obsolete tasks (*any tasks which are not found in the instance memory (runtime), but exists in the database*). Obsolete tasks may appear in cases when it wasn't cleared from the database on process shutdown, and/or was removed/renamed in the app. Obsolete tasks may appear if multiple app instances running different codebase within the same database, and the task may not exist on one of the instances. Default: `false`
103106
- `opts.resetOnInit` {*Boolean*} - [Optional] make sure all old tasks is completed before set new one. Useful when you run only one instance of app, or multiple app instances on one machine, in case machine was reloaded during running task and task is unfinished
104107
- `opts.zombieTime` {*Number*} - [Optional] time in milliseconds, after this time - task will be interpreted as "*zombie*". This parameter allows to rescue task from "*zombie* mode" in case when: `ready()` wasn't called, exception during runtime was thrown, or caused by bad logic. While `resetOnInit` option helps to make sure tasks are `done` on startup, `zombieTime` option helps to solve same issue, but during runtime. Default value is `900000` (*15 minutes*). It's not recommended to set this value to less than a minute (*60000ms*)
105-
- `opts.minRevolvingDelay` {*Number*} - [Optional] Minimum revolving delay — the minimum delay between tasks executions in milliseconds. Default: `32`
106-
- `opts.maxRevolvingDelay` {*Number*} - [Optional] Maximum revolving delay — the maximum delay between tasks executions in milliseconds. Default: `256`
108+
- `opts.minRevolvingDelay` {*Number*} - [Optional] Minimum revolving delay — the minimum delay between tasks executions in milliseconds. Default: `128`
109+
- `opts.maxRevolvingDelay` {*Number*} - [Optional] Maximum revolving delay — the maximum delay between tasks executions in milliseconds. Default: `768`
107110
- `opts.onError` {*Function*} - [Optional] Informational hook, called instead of throwing exceptions. Default: `false`. Called with two arguments:
108111
- `title` {*String*}
109112
- `details` {*Object*}
@@ -121,7 +124,22 @@ job.setInterval(task, 60 * 60 * 1000, 'task');
121124
### Initialization:
122125

123126
```js
124-
MongoClient.connect('url', (error, client) => {
127+
// Recommended MongoDB connection options
128+
// When used with ReplicaSet
129+
const options = {
130+
writeConcern: {
131+
j: true,
132+
w: 'majority',
133+
wtimeout: 30000
134+
},
135+
readConcern: {
136+
level: 'linearizable'
137+
},
138+
readPreference: 'primary',
139+
connectWithNoPrimary: false
140+
};
141+
142+
MongoClient.connect('url', options, (error, client) => {
125143
// To avoid "DB locks" — it's a good idea to use separate DB from "main" application DB
126144
const db = client.db('dbName');
127145
const job = new JoSk({db: db});

0 commit comments

Comments
 (0)