Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command that queues a job won't end #62

Open
Agilulfo1820 opened this issue Jan 28, 2021 · 3 comments
Open

Command that queues a job won't end #62

Agilulfo1820 opened this issue Jan 28, 2021 · 3 comments

Comments

@Agilulfo1820
Copy link

Description of bug

Add a job queue library (ex Adonis Bull)
Create a job with a console log in the handle method
Create an ace command that queues the job inside the handle method

Result: Job will be executed but the command won't end (close it with CTRL+C)
Expected result: job is triggered and command closes correctly.


'use strict'

const {Command} = require('@adonisjs/ace')
const Bull = use('Rocketseat/Bull')
const ImportTagsJob = use('App/Jobs/ImportTagsJob')
const Database = use('Database')
const Redis = use('Redis')

class ImportTags extends Command {
    static get signature() {
        return 'process:imported-tags'
    }

    static get description() {
        return 'Import nfc and rfid tags from S3'
    }

    async handle() {
        Bull.add(ImportTagsJob.key)

        await Database.close()
        await Redis.quit()
    }
}

module.exports = ImportTags

Environment:
"adonis-version": "4.1.0",
node v12.18.2
npm 6.14.10

Additional context

I also opened an issue on adonis/core (adonisjs/core#2184).
What @thetutlage is saying is that Bull opens their connection to Redis so I have to somehow close that connection and not the one of Adonis Provider.

@HigoRibeiro
Copy link
Contributor

Hi @Agilulfo1820 !!
Could you try this?

async handle() {
  const job = await Bull.add(ImportTagsJob.key)
  await job.queue.close()
}

In the Bull's doc there's the Queue#close to disconnect from the redis client.
I think that solves the problem of keeping alive.

@Agilulfo1820
Copy link
Author

Hi @Agilulfo1820 !!
Could you try this?

async handle() {
  const job = await Bull.add(ImportTagsJob.key)
  await job.queue.close()
}

In the Bull's doc there's the Queue#close to disconnect from the redis client.
I think that solves the problem of keeping alive.

Sorry, still doesn't end :/

@Agilulfo1820
Copy link
Author

Still here. I am using process.exit(0) to close the command while the job was queued but I noticed that each time it does that my db connection is being aborted:

2021-06-16 17:27:05 98 [Warning] Aborted connection 98 to db: 'homestead' user: 'root' host: '172.24.0.1' (Got an error reading communication packets)

So this solution is not obtimal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants