File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ export abstract class Job<Payload = any> {
3838 return dispatcher
3939 }
4040
41- abstract execute ( ) : Promise < void >
41+ abstract execute ( signal ?: AbortSignal ) : Promise < void >
4242
4343 failed ?( error : Error ) : Promise < void >
4444}
Original file line number Diff line number Diff line change @@ -257,11 +257,15 @@ export class Worker {
257257 return instance . execute ( )
258258 }
259259
260- const timeoutPromise = setTimeout ( timeout ) . then ( ( ) => {
261- throw new errors . E_JOB_TIMEOUT ( [ instance . constructor . name , timeout ] )
260+ const signal = AbortSignal . timeout ( timeout )
261+
262+ const abortPromise = new Promise < never > ( ( _ , reject ) => {
263+ signal . addEventListener ( 'abort' , ( ) => {
264+ reject ( new errors . E_JOB_TIMEOUT ( [ instance . constructor . name , timeout ] ) )
265+ } )
262266 } )
263267
264- await Promise . race ( [ instance . execute ( ) , timeoutPromise ] )
268+ await Promise . race ( [ instance . execute ( signal ) , abortPromise ] )
265269 }
266270
267271 async #acquireNextJob( queues : string [ ] ) : Promise < { job : AcquiredJob ; queue : string } | null > {
You can’t perform that action at this time.
0 commit comments