Options
All
  • Public
  • Public/Protected
  • All
Menu

Class JobProcessor

Hierarchy

  • JobProcessor

Index

Constructors

constructor

  • new JobProcessor(agenda: Agenda, maxConcurrency: number, totalLockLimit: number, processEvery: number): JobProcessor

Properties

Private agenda

agenda: Agenda

Private isLockingOnTheFly

isLockingOnTheFly: boolean = false

Private isRunning

isRunning: boolean = true

Private jobQueue

jobQueue: JobProcessingQueue = new JobProcessingQueue(this.agenda)

Private jobStatus

jobStatus: {}

Type declaration

  • [name: string]: { locked: number; running: number } | undefined

Private jobsToLock

jobsToLock: JobWithId[] = []

Private localQueueProcessing

localQueueProcessing: number = 0

Private lockedJobs

lockedJobs: JobWithId[] = []

Private maxConcurrency

maxConcurrency: number

Private nextScanAt

nextScanAt: Date = new Date()

Private processEvery

processEvery: number

Private Optional processInterval

processInterval: ReturnType<typeof setInterval>

Private runningJobs

runningJobs: JobWithId[] = []

Private totalLockLimit

totalLockLimit: number

Methods

Private enqueueJob

  • enqueueJob(job: Job): void
  • Internal method that adds jobs to be processed to the local queue

    Parameters

    Returns void

Private findAndLockNextJob

getStatus

Private jobProcessing

  • jobProcessing(handledJobs?: IJobParameters["_id"][]): void
  • Internal method that processes any jobs in the local queue (array) handledJobs keeps list of already processed jobs

    Parameters

    • Default value handledJobs: IJobParameters["_id"][] = []

    Returns void

Private jobQueueFilling

  • jobQueueFilling(name: string): Promise<void>
  • Internal method used to fill a queue with jobs that can be run

    Parameters

    • name: string

      fill a queue with specific job name

    Returns Promise<void>

lockOnTheFly

  • lockOnTheFly(): Promise<void>
  • Internal method that will lock a job and store it on MongoDB This method is called when we immediately start to process a job without using the process interval We do this because sometimes jobs are scheduled but will be run before the next process time

    Returns Promise<void>

process

  • process(extraJob?: JobWithId): Promise<void>

Private runOrRetry

  • Internal method that tries to run a job and if it fails, retries again!

    Parameters

    Returns Promise<void>

    processed a job or not

shouldLock

  • shouldLock(name: string): boolean
  • Returns true if a job of the specified name can be locked. Considers maximum locked jobs at any time if self._lockLimit is > 0 Considers maximum locked jobs of the specified name at any time if jobDefinition.lockLimit is > 0

    Parameters

    • name: string

      name of job to check if we should lock or not

    Returns boolean

    whether or not you should lock job

stop

Private updateStatus

  • updateStatus(name: string, key: "locked" | "running", number: -1 | 1): void

Generated using TypeDoc