5.0.1 • Published 6 years ago

adonis-kue v5.0.1

Weekly downloads
228
License
MIT
Repository
github
Last release
6 years ago

Adonis Kue Provider

A 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:

const providers = [
  ...
  'adonis-kue/providers/KueProvider'
]

Register the commands provider in start/app.js:

const aceProviders = [
  ...
  'adonis-kue/providers/CommandsProvider'
]

Register the jobs in start/app.js:

const jobs = [
  ...
  'App/Jobs/Example'
]

And then export the jobs array:

module.exports = { providers, aceProviders, aliases, commands, jobs }

Add a configuration file in config/kue.js. For example:

'use strict'

const Env = use('Env')

module.exports = {
  // redis connection
  connection: Env.get('KUE_CONNECTION', 'kue')
}

Usage

Command List

CommandDescription
adonis kue:listenStarting the listener
adonis make:jobMake 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:

NameRequiredTypeStaticDescription
concurrencyfalsenumbertrueThe number of concurrent jobs the handler will accept
keytruestringtrueA unique key for this job
handletruefunctionfalseA function that is called for this job.

Here's an example.

Dispatching jobs

Now that your job listener is running and ready to do some asynchronous work, you can start dispatching jobs.

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 for creating such a great framework.

5.0.1

6 years ago

5.0.0

6 years ago

4.0.0

6 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.2

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.0

8 years ago