adonis-bull icon indicating copy to clipboard operation
adonis-bull copied to clipboard

Command that queues a job won't end

Open Agilulfo1820 opened this issue 3 years ago • 3 comments

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 (https://github.com/adonisjs/core/issues/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.

Agilulfo1820 avatar Jan 28 '21 10:01 Agilulfo1820

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.

HigoRibeiro avatar Jan 30 '21 01:01 HigoRibeiro

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 avatar Jan 30 '21 11:01 Agilulfo1820

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.

Agilulfo1820 avatar Jun 16 '21 17:06 Agilulfo1820