All files / src/queues/jobs BaseJob.ts

100% Statements 7/7
100% Branches 3/3
100% Functions 3/3
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39      24x   24x   24x     13x 1x   12x       5x                                          
export abstract class BaseJob {
  abstract readonly id: string
 
  readonly retryable: boolean = true
 
  readonly startDelay: number = 0
 
  readonly retryDelay: number = 60
 
  getStartDelay(asap: boolean = false): number {
    if (asap) {
      return 2000 // 2 seconds
    }
    return this.startDelay * 1000
  }
 
  getRetryDelay(retryCount: number): number {
    return retryCount * this.retryDelay * 1000
  }
 
  async init(): Promise<void> {}
}
 
export abstract class SimpleJob extends BaseJob {
  abstract run(): Promise<void>
}
 
export abstract class TransactionJob extends BaseJob {
  abstract run(transactionId: string): Promise<void>
}
 
export abstract class BudgetJob extends BaseJob {
  abstract run(budgetId: string): Promise<void>
}
 
export abstract class EndpointJob extends BaseJob {
  abstract run(transactionId: string, data: unknown): Promise<void>
}