Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eknkc/minwq
Minimalistic node.js work queue backed by redis
https://github.com/eknkc/minwq
Last synced: about 2 months ago
JSON representation
Minimalistic node.js work queue backed by redis
- Host: GitHub
- URL: https://github.com/eknkc/minwq
- Owner: eknkc
- Created: 2013-06-29T23:11:25.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-03-18T23:23:01.000Z (almost 10 years ago)
- Last Synced: 2024-10-05T11:36:31.997Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 193 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# minwq
Minimalistic Node.JS Work Queue, backed by Redis. (>=2.6.* redis required with Lua support)npm install minwq
##Usage
var minwq = require("minwq")// Create a new store
var store= new minwq([options]);// Optional
// You can provide a queue suffix for all jobs for namespacing purposes.
var store = new minwq({
prefix: "myapp",
});// If you need to provide custom redis clients (due to authentication or because you just want to), you can override createClient function of store;
minwq.prototype.createClient = function() {
return redis.createClient(..whatever);
}#### Pushing - Push a new job to a queue
* `queue` [required] - Name of the queue
* `data` [required] - Job payload
* `delay` [optional] - Delay job execution (in milliseconds)
* `unique` [optional] - If provided, only a single living job can have the unqiue token, additional push requests will fail.
* `replace` [optional] - Boolean. If a unique key is provided and a duplicate job is pushed, it is ignored by default. Provide replace: true to replace the older job with new one.
* `callback(err, jobid)` - Gets called when the job is created***
```
store.push({
queue: "email",
data: {
to: "[email protected]",
subject: "Foo",
text: "Bar"
},
delay: 100,
unique: "unqiue token",
}, callback);
```#### Poping - Pop a job from queue
* `ttl` [optional] - Job retry delay (in milliseconds).
If a job takes more than `ttl` milliseconds to complete, it will be requeued.
No TTL means the hob will be removed from queue immediately when the pop function gets called.***
```
store.pop({
queue: "email",
ttl: 10000
}, function(err, job) {
// job.data contains the job payload
console.log(job.data);// after finishing the job, you need to remove it explicitly from the queue:
job.remove(callback);
});
```##license
MIT