Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nrempel/adonis-kue
An AdonisJS provider for Kue
https://github.com/nrempel/adonis-kue
adonis adonisjs job kue queue worker
Last synced: 3 months ago
JSON representation
An AdonisJS provider for Kue
- Host: GitHub
- URL: https://github.com/nrempel/adonis-kue
- Owner: nrempel
- License: mit
- Created: 2016-06-22T00:53:39.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-18T19:09:31.000Z (over 4 years ago)
- Last Synced: 2024-08-01T04:59:01.380Z (3 months ago)
- Topics: adonis, adonisjs, job, kue, queue, worker
- Language: JavaScript
- Homepage: https://github.com/nrempel/adonis-kue
- Size: 166 KB
- Stars: 87
- Watchers: 5
- Forks: 24
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Adonis Kue Provider
A [Kue](https://github.com/Automattic/kue) provider for the Adonis framework.
This library provides an easy way to get started with an asynchronous job queue for AdonisJS.
## Install
```
npm install --save adonis-kue
```## Configure
Register the kue provider in `start/app.js`:
```javascript
const providers = [
...
'adonis-kue/providers/KueProvider'
]
```Register the commands provider in `start/app.js`:
```javascript
const aceProviders = [
...
'adonis-kue/providers/CommandsProvider'
]
```Register the jobs in `start/app.js`:
```javascript
const jobs = [
...
'App/Jobs/Example'
]
```And then export the `jobs` array:
```js
module.exports = { providers, aceProviders, aliases, commands, jobs }
```Add a configuration file in `config/kue.js`. For example:
```javascript
'use strict'const Env = use('Env')
module.exports = {
// redis connection
connection: Env.get('KUE_CONNECTION', 'kue')
}
```## Usage
### Command List
Command | Description
:---------------------|:-----------
`adonis kue:listen` | Starting the listener
`adonis make:job` | Make a new Job (Queue)### Starting the listener
Starting an instance of the kue listener is easy with the included ace command. Simply run `./ace kue:listen` or `adonis kue:listen`.
### Creating your first job
They expose the following properties:
| Name | Required | Type | Static | Description |
|-------------|----------|-----------|--------|-------------------------------------------------------|
| concurrency | false | number | true | The number of concurrent jobs the handler will accept |
| key | true | string | true | A unique key for this job |
| handle | true | function | false | A function that is called for this job. |[Here's an example.](examples/app/Jobs/Example.js)
### Dispatching jobs
Now that your job listener is running and ready to do some asynchronous work, you can start dispatching jobs.
```javascript
const kue = use('Kue')
const Job = use('App/Jobs/Example')
const data = { test: 'data' } // Data to be passed to job handle
const priority = 'normal' // Priority of job, can be low, normal, medium, high or critical
const attempts = 1 // Number of times to attempt job if it fails
const remove = true // Should jobs be automatically removed on completion
const jobFn = job => { // Function to be run on the job before it is saved
job.backoff()
}
const job = kue.dispatch(Job.key, data, { priority, attempts, remove, jobFn })// If you want to wait on the result, you can do this
const result = await job.result
```## Thanks
Special thanks to the creator(s) of [AdonisJS](http://adonisjs.com/) for creating such a great framework.