1- import { logger , stopwatch } from '@hirosystems/api-toolkit' ;
1+ import { logger , resolveOrTimeout , stopwatch } from '@hirosystems/api-toolkit' ;
22import { ENV } from '../../../env' ;
33import { PgStore } from '../../../pg/pg-store' ;
44import { DbJob , DbJobInvalidReason , DbJobStatus } from '../../../pg/types' ;
@@ -43,8 +43,13 @@ export abstract class Job {
4343 // what to do in each case. If we choose to retry, this queue entry will simply not be marked as
4444 // `processed = true` so it can be picked up by the queue at a later time.
4545 try {
46- await this . handler ( ) ;
47- status = DbJobStatus . done ;
46+ const success = await resolveOrTimeout ( this . handler ( ) , ENV . JOB_QUEUE_TIMEOUT_MS ) ;
47+ if ( success ) {
48+ status = DbJobStatus . done ;
49+ } else {
50+ logger . error ( `Job ${ this . description ( ) } allowed timeout exceeded` ) ;
51+ status = DbJobStatus . failed ;
52+ }
4853 } catch ( error ) {
4954 if ( error instanceof RetryableJobError ) {
5055 const retries = await this . db . increaseJobRetryCount ( { id : this . job . id } ) ;
@@ -62,7 +67,7 @@ export abstract class Job {
6267 status = DbJobStatus . failed ;
6368 }
6469 } else if ( error instanceof UserError ) {
65- logger . error ( error , `User error on Job ${ this . description ( ) } ` ) ;
70+ logger . warn ( error , `User error on Job ${ this . description ( ) } ` ) ;
6671 status = DbJobStatus . invalid ;
6772 invalidReason = getUserErrorInvalidReason ( error ) ;
6873 } else {
0 commit comments