Skip to content

Commit

Permalink
feat: add the make exception command
Browse files Browse the repository at this point in the history
  • Loading branch information
HigoRibeiro authored and jpedroschmitz committed Jan 26, 2021
1 parent 7abcb81 commit ac7738f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
26 changes: 26 additions & 0 deletions commands/MakeException.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { join } from 'path'
import { BaseCommand } from '@adonisjs/core/build/standalone'

export default class MakeException extends BaseCommand {
public static commandName = 'bull:exception'
public static description = 'Make a Bull exception handle file'

/**
* Execute command
*/
public async run (): Promise<void> {
const stub = join(__dirname, '..', 'templates', 'handler.txt')

const path = this.application.resolveNamespaceDirectory('exceptions')
const rootDir = this.application.cliCwd || this.application.appRoot

this.generator
.addFile('BullHandler.ts')
.stub(stub)
.destinationDir(path || 'app/Exceptions')
.useMustache()
.appRoot(rootDir)

await this.generator.run()
}
}
1 change: 1 addition & 0 deletions commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default [
'@rocketseat/adonis-bull/build/commands/MakeJob',
'@rocketseat/adonis-bull/build/commands/MakeException',
'@rocketseat/adonis-bull/build/commands/Listen'
]
11 changes: 8 additions & 3 deletions templates/handler.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@
|
*/

import Logger from '@ioc:Adonis/Core/Logger'
import BullExceptionHandler from '@ioc:Rocketseat/Bull/BullExceptionHandler'
import { Job } from '@ioc:Rocketseat/Bull'
import Logger from '@ioc:Adonis/Core/Logger'

export default class BullHandler extends BullExceptionHandler {
constructor() {
export default class JobExceptionHandler extends BullExceptionHandler {
constructor () {
super(Logger)
}

public async handle (error: Error, job: Job) {
this.logger.error(`key=${job.name} id=${job.id} error=${error.message}`)
}
}

0 comments on commit ac7738f

Please sign in to comment.