I was trying to insert a user to users table and it was successful but the command does not terminate after yield user.save(). I think the iterator is in infinite loop.
Model:
'use strict'
const Lucid = use('Lucid')
class User extends Lucid {
}
module.exports = User
Command:
'use strict'
const Command = use('Command')
const User = use('App/Model/User')
class CreateUser extends Command {
get signature() {
return 'createUser {userName}'
}
get description() {
return 'This will create and insert a user to DB'
}
* handle(args, options) {
const user = new User()
user.username = args.userName
yield user.save() // Success, but wont terminate after this line
}
}
module.exports = CreateUser
Database connections are long lived connections and you are required to close them manually. For ace commands you can do
const Database = use('Database')
* handle(args, options) {
const user = new User()
user.username = args.userName
yield user.save() // Success, but wont terminate after this line
Database.close()
}
@thetutlage Thanks for the fast reply! :)
Closing 😄
Would be nice to have a caveat or something in the docs related to this
http://adonisjs.com/docs/3.2/interactive-shell#_creating_your_first_command
just want to add a note here in case others having the issue even after Database.close()
in my case, I also need closing Redis connections because my ace command is writing to Redis as well
// v3
yield use('Redis').quit('default')
I've got similar problem but with Mail. I'm sending notification emails using SMTP driver. Mails are sent but the command does not terminate. Any help please?
make sure all the external connections (e.g. database, redis) are all
explicitly closed
On Wed, 12 Dec 2018 at 8:42 PM, Zombi notifications@github.com wrote:
I've got similar problem but with Mail. I'm sending notification emails
using SMTP driver. Mails are sent but the command does not terminate. Any
help please?—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/adonisjs/adonis-framework/issues/227#issuecomment-446574969,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AANpQ1qQ7F9GLeVrK84Goxnc1OBpapDGks5u4PmwgaJpZM4JW71D
.
I do. I saw Databse.close() in doc example, so I close the Database like mentioned but Mail is what makes problems. I'm sending email after query - when I use Mail.fake() its OK but after Mail.send() command is not terminated I was looking for some "Mail.close()" but no success.
@LordZombi
Mail.connection()._driverInstance.transporter.close()
@3dd13 thanks for the workaround it works!
But I think Adonis can make nicer implementation :) This is kind oh hack when working with private variables (_driverInstance)
Still big thanks.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
@LordZombi
TL;DR
my troubleshooting steps
underlying source code references