mirror of
https://fast.feibisi.com/https://github.com/parcelvoy/platform.git
synced 2025-08-29 11:56:04 +08:00
Improve queue error handling (#120)
This commit is contained in:
parent
09f4ab938f
commit
a5b4f62d29
4 changed files with 15 additions and 9 deletions
|
@ -26,7 +26,9 @@ export default class BugSnagProvider implements ErrorHandlingProvider {
|
|||
}
|
||||
}
|
||||
|
||||
notify(error: Error) {
|
||||
Bugsnag.notify(error)
|
||||
notify(error: Error, context?: Record<string, any>) {
|
||||
Bugsnag.notify(error, (event) => {
|
||||
context && event.addMetadata('context', context)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ export default class ErrorHandler {
|
|||
this.provider?.attach(api)
|
||||
}
|
||||
|
||||
notify(error: Error) {
|
||||
this.provider?.notify(error)
|
||||
notify(error: Error, context?: Record<string, any>) {
|
||||
this.provider?.notify(error, context)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,5 +4,5 @@ export type ErrorHandlerProviderName = 'bugsnag' | 'sentry'
|
|||
|
||||
export default interface ErrorHandlerProvider {
|
||||
attach(api: Koa): void
|
||||
notify(error: Error): void
|
||||
notify(error: Error, context?: Record<string, any>): void
|
||||
}
|
||||
|
|
|
@ -31,9 +31,13 @@ export default class Queue {
|
|||
}
|
||||
|
||||
async dequeue(job: EncodedJob): Promise<boolean> {
|
||||
await this.started(job)
|
||||
await this.jobs[job.name](job.data)
|
||||
await this.completed(job)
|
||||
try {
|
||||
await this.started(job)
|
||||
await this.jobs[job.name](job.data)
|
||||
await this.completed(job)
|
||||
} catch (error: any) {
|
||||
this.errored(job, error)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -62,7 +66,7 @@ export default class Queue {
|
|||
|
||||
async errored(job: EncodedJob | undefined, error: Error) {
|
||||
logger.error({ error, job }, 'queue:job:errored')
|
||||
App.main.error.notify(error)
|
||||
App.main.error.notify(error, job)
|
||||
}
|
||||
|
||||
async completed(job: EncodedJob) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue