Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/titarenko/worque
AMQP-based work queue.
https://github.com/titarenko/worque
Last synced: about 1 month ago
JSON representation
AMQP-based work queue.
- Host: GitHub
- URL: https://github.com/titarenko/worque
- Owner: titarenko
- Created: 2014-06-18T19:10:50.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-12-09T22:36:25.000Z (about 7 years ago)
- Last Synced: 2024-12-01T03:46:02.195Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 37.1 KB
- Stars: 11
- Watchers: 3
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# worque
AMQP-based work queue.
[![Build Status](https://secure.travis-ci.org/titarenko/worque.png?branch=master)](https://travis-ci.org/titarenko/worque) [![Coverage Status](https://coveralls.io/repos/titarenko/worque/badge.png)](https://coveralls.io/r/titarenko/worque)
## Installation
```bash
npm i worque --save
```## Description
Each `task` = `queue`.
Publishing message = loading single worker with task.
NOTE: one-by-one task processing is guaranteed only with RabbitMQ 3.3 and higher.
## Motivation
- simple project bootstrap
- task survives broker restarts
- task waits for worker (handler) if it's offline
- task can be scheduled (cron)
- task can be retried with flexible and easy-to-specify retry period configuration
- fluent and simple API## Example
```js
var client = require('worque')('amqp://localhost');// global (all tasks) events
client.on('task', console.log); // fired before handler
client.on('result', console.log); // fired after handler
client.on('failure', console.error); // fired if handler fails// define task 'logthis' and provide handler
client('logthis').subscribe(function (message) {
console.log(message);
});// start 'logthis' task with params
client('logthis').publish({ something: 42 });// setup scheduled task
client('recurrent task runs each minute').subscribe(function () {
console.log('I run each minute');
}).schedule('0 * * * * *');// will be retried (republished) 1 second after 1st failure
// 2 seconds after 2nd failure
// 3 seconds after 3d failure
client('retry 3 times if failed').subscribe(function (url) {
return doRequestAndSaveToFile(url);
}).retry(1, 2, 3).publish('http://mysite.com');process.on('SIGINT', function () {
client.close();
});
```## License
MIT