nrempel / adonis-kue Goto Github PK
View Code? Open in Web Editor NEWAn AdonisJS provider for Kue
Home Page: https://github.com/nrempel/adonis-kue
License: MIT License
An AdonisJS provider for Kue
Home Page: https://github.com/nrempel/adonis-kue
License: MIT License
Is this integration compatible with version 4 of Adonis?
It was working fine when has less than 4 jobs, but when put the 4th Job to works, the message above starts::
(node:114256) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 job ttl exceeded listeners added. Use emitter.setMaxListeners() to increase limit
Currently, only the job payload is passed to the handle()
method of a job class, I think it could be better to inject the job object and the done()
callback too in order to have the same abilities as the default kue API (cf queue.process()
method).
You probably want to provide an higher level API in the job classes, but sometime you need to use job.progress()
or job.log()
inside the job handler, or use the done()
callback to return job specific errors, or complete the job programmatically.
Hi. Congrats!!! Great package!!
How can i configure it to listen in a linux server with PM2 ?
I am not understanding the set up. New to queue. Could you please tell me KUE_CONNECTION in kue.js file? I created this kue.js file. what should I pass there.
I'm a bit confused to set up adonis-kue.
I followed step by step the readme documentation, and even then I have had problems getting it to work. When I go to dispatch a job, it returns the following error.
2018-02-22T20:19:31.792Z - warning:
WARNING: Adonis has detected an unhandled promise rejection, which may
cause undesired behavior in production.
To stop this warning, use catch() on promises and wrap await
calls inside try/catch.
RuntimeException: E_MISSING_CONFIG: redis://localhost:6379 is not defined inside config/redis.js file
> More details: https://err.sh/adonisjs/errors/E_MISSING_CONFIG
at Function.missingConfig (/home/daniel/dev/vacinadigital/api/monolith/node_modules/@adonisjs/redis/node_modules/@adonisjs/generic-exceptions/src/RuntimeException.js:38:12)
at Proxy.connection (/home/daniel/dev/vacinadigital/api/monolith/node_modules/@adonisjs/redis/src/Redis/index.js:92:33)
at createClientFactory (/home/daniel/dev/vacinadigital/api/monolith/node_modules/adonis-kue/src/Kue/index.js:30:39)
at Object.exports.createClient (/home/daniel/dev/vacinadigital/api/monolith/node_modules/kue/lib/redis.js:62:31)
at new Queue (/home/daniel/dev/vacinadigital/api/monolith/node_modules/kue/lib/kue.js:99:52)
at Function.exports.createQueue (/home/daniel/dev/vacinadigital/api/monolith/node_modules/kue/lib/kue.js:70:23)
at Kue.get instance [as instance] (/home/daniel/dev/vacinadigital/api/monolith/node_modules/adonis-kue/src/Kue/index.js:44:28)
at Kue.dispatch (/home/daniel/dev/vacinadigital/api/monolith/node_modules/adonis-kue/src/Kue/index.js:63:22)
at Object.TokenHook.addTokenQueue (/home/daniel/dev/vacinadigital/api/monolith/app/Models/Hooks/TokenHook.js:18:19)
at Hooks.exec (/home/daniel/dev/vacinadigital/api/monolith/node_modules/@adonisjs/lucid/src/Lucid/Hooks/index.js:166:13)
at Proxy._insert (/home/daniel/dev/vacinadigital/api/monolith/node_modules/@adonisjs/lucid/src/Lucid/Model/index.js:695:41)
at <anonymous>
Now I will show my settings:
# kue
KUE_CONNECTION=redis://localhost:6379
# redis
REDIS_CONNECTION=local
config/redis.js
'use strict'
/*
|--------------------------------------------------------------------------
| Redis Configuaration
|--------------------------------------------------------------------------
|
| Here we define the configuration for redis server. A single application
| can make use of multiple redis connections using the redis provider.
|
*/
const Env = use('Env')
module.exports = {
/*
|--------------------------------------------------------------------------
| connection
|--------------------------------------------------------------------------
|
| Redis connection to be used by default.
|
*/
connection: Env.get('REDIS_CONNECTION', 'local'),
/*
|--------------------------------------------------------------------------
| local connection config
|--------------------------------------------------------------------------
|
| Configuration for a named connection.
|
*/
local: {
host: '127.0.0.1',
port: 6379,
password: null,
db: 0,
keyPrefix: ''
},
/*
|--------------------------------------------------------------------------
| cluster config
|--------------------------------------------------------------------------
|
| Below is the configuration for the redis cluster.
|
*/
cluster: {
clusters: [{
host: '127.0.0.1',
port: 6379,
password: null,
db: 0
},
{
host: '127.0.0.1',
port: 6380,
password: null,
db: 0
}]
}
}
config/kue.js
'use strict'
const Env = use('Env')
module.exports = {
// redis connection
connection: Env.get('KUE_CONNECTION', 'kue')
}
Something that passed in my eyes?
Is there a possibility to view and manage the jobs with kue-dashboard?
RuntimeException: E_MISSING_CONFIG: redis://localhost:6379 is not defined inside config/redis.js file
More details: https://err.sh/adonisjs/errors/E_MISSING_CONFIG
I copied the config here
https://github.com/nrempel/adonis-kue/tree/master/examples/config
my .env
# KUE
KUE_CONNECTION=redis://localhost:6379
# REDIS
REDIS_CONNECTION=local
I'm trying to enqueue a Kue Job from a Command, but command doesn't terminate and it keeps running.
Do I have to do something inside the command to close the process from the job?
// This is where the work is done.
async handle(data) {
await Mail.connection('mailgun')
.raw(
`<a href="${data.latestChapterLink}" target="_blank">${
data.latestChapterLink
}</a>`,
message => {
message.subject(data.mailSubject)
message.text(data.latestChapterLink)
message.from(`NovelNotifier<[email protected]>`)
message.to(data.userEmail)
}
)
.catch(err => {
// Mark job as fail and log err so I can view it at failed jobs in kue-dashboard
})
}
Will the command be made to create the jobs template?
How to set this configuration?
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 job ttl exceeded listeners added. Use emitter.setMaxListeners() to increase limit
Hi,
Is it possible to create different queues? I want to have several workers processing different queues with different kind of jobs.
I think in kue it is possible passing an option object with name property to the createQueue function.
Thank you
It'd be nice for the removeOnComplete
option to be a configuration option. I might submit a PR shortly.
@nrempel I have taken a look at both your implementations of adonis-queue and adonis-kue. Can I ask why you switched to bull over kue in adonis-queue? Do you you feel one library does a better job than the other?
I have just integrated adonis-kue into my application, and at the same time extended the API. I was going to create a PR to incorporate my additions to the library and then I came across adonis-queue.
I can see that the API for adonis-queue is very similar to that of its kue counterpart. Would it be wise for me to create a PR for both libraries, since my changes can extend both packages? Or are you only going to be maintaining one of these packages?
Hi,
In kue, you can do:
kue.Job.get(11, function(err, job){
console.log(job.type)
})
But when you are using adonis-kue provider the Job object is not exported so you have to require kue directly in order to get it. I think it would be a good idea to export it too in the provider to avoid to require kue directly.
I'd like to bring to notice that Kue is no longer being maintained. https://github.com/Automattic/kue#kue-is-no-longer-maintained
https://twitter.com/automattic/status/1019073146446602240
Thank you for building this and introducing me to Kue! This could be very useful for a project I'm working on.
Is it possible to start the kue listener as part of the main server.js script? I can edit server.js and spawn a child process in there but this doesn't feel the most elegant solution.
Even when it falls into catch
, it does not retry. I'd like you to do it, how's it going?
'use strict'
const Mail = use('Mail')
const Env = use('Env')
class SendEmail {
// If this getter isn't provided, it will default to 1.
// Increase this number to increase processing concurrency.
static get concurrency () {
return 1
}
// This is required. This is a unique key used to identify this job.
static get key () {
return 'send-email'
}
// This is where the work is done.
async handle (data) {
try {
const content = Object.assign(data, { appUrl: Env.get('APP_SITE') })
const test = await Mail.send(data.template, content, (message) => {
message.from('[email protected]')
message.to(data.email)
message.subject(data.subject)
})
} catch (e) {
// He does not try when he falls here.
console.log(e)
}
}
}
module.exports = SendEmail
Dispatch:
try {
// GET EMAIL, NAME OF USER
const userInstance = await User.findOrFail(tokenInstance.user_id)
const subject = tokenInstance => tokenInstance.type === 'activate' ? 'Ativar sua conta' : 'Alteração de senha'
const data = {
content: {
token: tokenInstance,
user: userInstance
},
template: 'emails.token',
subject: subject(tokenInstance),
email: userInstance.email
}
const priority = 'medium' // Priority of job, can be low, normal, medium, high or critical
const attempts = 5 // Number of times to attempt job if it fails
const remove = true // Should jobs be automatically removed on completion
const job = kue.dispatch(Job.key, data, priority, attempts, remove)
} catch (e) {
console.log(e)
}
Hi,
I have done the setup as in docs, but when i run kue:listen i get info: kue worker listening for 0 job(s)
in terminal, and nothing happens.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.