bullmq - v5.56.2
    Preparing search index...

    Class Job<DataType, ReturnType, NameType>

    Job

    This class represents a Job in the queue. Normally job are implicitly created when you add a job to the queue with methods such as Queue.addJob( ... )

    A Job instance is also passed to the Worker's process function.

    Type Parameters

    • DataType = any
    • ReturnType = any
    • NameType extends string = string

    Implements

    Index

    Constructors

    Properties

    attemptsMade: number = 0

    Number of attempts after the job has failed.

    0
    
    attemptsStarted: number = 0

    Number of attempts when job is moved to active.

    0
    
    data: DataType

    The payload for this job.

    debounceId?: string

    Debounce identifier.

    use deduplicationId

    deduplicationId?: string

    Deduplication identifier.

    deferredFailure: string

    Deferred failure. Stores a failed message and marks this job to be failed directly as soon as the job is picked up by a worker, and using this string as the failed reason.

    delay: number = 0

    An amount of milliseconds to wait until this job can be processed.

    0
    
    failedReason: string

    Reason for failing.

    finishedOn?: number

    Timestamp for when the job finished (completed or failed).

    id?: string
    name: NameType

    The name of the Job

    nextRepeatableJobId?: string

    Produced next repetable job Id.

    opts: JobsOptions = {}

    The options object for this job.

    parent?: ParentKeys

    Object that contains parentId (id) and parent queueKey.

    parentKey?: string

    Fully qualified key (including the queue prefix) pointing to the parent of this job.

    priority: number = 0

    Ranges from 0 (highest priority) to 2 097 152 (lowest priority). Note that using priorities has a slight impact on performance, so do not use it if not required.

    0
    
    processedBy?: string

    The worker name that is processing or processed this job.

    processedOn?: number

    Timestamp for when the job was processed.

    progress: JobProgress = 0

    The progress a job has performed so far.

    0
    
    queueQualifiedName: string

    It includes the prefix, the namespace separator :, and queue name.

    repeatJobKey?: string

    Base repeat job key.

    returnvalue: ReturnType = null

    The value returned by the processor when processing this job.

    null
    
    stacktrace: string[] = null

    Stacktrace for the error (for failed jobs).

    null
    
    stalledCounter: number = 0

    Number of times where job has stalled.

    0
    
    timestamp: number

    Timestamp when the job was created (unless overridden with job options).

    token?: string

    The token used for locking this job.

    Accessors

    • get prefix(): string

      Returns string

      the prefix that is used.

    • get queueName(): string

      Returns string

      the queue name this job belongs to.

    Methods

    • Change delay of a delayed job.

      Parameters

      • delay: number

        milliseconds to be added to current time.

      Returns Promise<void>

      void

    • Change job priority.

      Parameters

      • opts: { lifo?: boolean; priority?: number }

        options containing priority and lifo values.

      Returns Promise<void>

      void

    • Clears job's logs

      Parameters

      • OptionalkeepLogs: number

        the amount of log entries to preserve

      Returns Promise<void>

    • Marks a job to not be retried if it fails (even if attempts has been configured)

      Returns void

      use UnrecoverableError

    • Extend the lock for this job.

      Parameters

      • token: string

        unique token for the lock

      • duration: number

        lock duration in milliseconds

      Returns Promise<number>

    • Get this jobs children result values if any.

      Type Parameters

      • CT = any

      Returns Promise<{ [jobKey: string]: CT }>

      Object mapping children job keys with their values.

    • Get children job keys if this job is a parent and has children.

      Parameters

      Returns Promise<
          {
              failed?: string[];
              ignored?: Record<string, any>;
              nextFailedCursor?: number;
              nextIgnoredCursor?: number;
              nextProcessedCursor?: number;
              nextUnprocessedCursor?: number;
              processed?: Record<string, any>;
              unprocessed?: string[];
          },
      >

      dependencies separated by processed, unprocessed, ignored and failed.

      Count options before Redis v7.2 works as expected with any quantity of entries on processed/unprocessed dependencies, since v7.2 you must consider that count won't have any effect until processed/unprocessed dependencies have a length greater than 127

    • Get children job counts if this job is a parent and has children.

      Parameters

      • opts: {
            failed?: boolean;
            ignored?: boolean;
            processed?: boolean;
            unprocessed?: boolean;
        } = {}

      Returns Promise<
          {
              failed?: number;
              ignored?: number;
              processed?: number;
              unprocessed?: number;
          },
      >

      dependencies count separated by processed, unprocessed, ignored and failed.

    • Get job's children failure values that were ignored if any.

      Returns Promise<{ [jobKey: string]: string }>

      Object mapping children job keys with their failure values.

      This method is deprecated and will be removed in v6. Use getIgnoredChildrenFailures instead.

    • Retrieves the failures of child jobs that were explicitly ignored while using ignoreDependencyOnFailure option. This method is useful for inspecting which child jobs were intentionally ignored when an error occured.

      Returns Promise<{ [jobKey: string]: string }>

      Object mapping children job keys with their failure values.

    • Get current state.

      Returns Promise<"unknown" | JobState>

      Returns one of these values: 'completed', 'failed', 'delayed', 'active', 'waiting', 'waiting-children', 'unknown'.

    • Returns Promise<boolean>

      true of the job is active.

    • Returns Promise<boolean>

      true if the job has completed.

    • Returns Promise<boolean>

      true if the job is delayed.

    • Returns Promise<boolean>

      true if the job has failed.

    • Returns Promise<boolean>

      true if the job is waiting.

    • Returns Promise<boolean>

      true if the job is waiting for children.

    • Logs one row of log data.

      Parameters

      • logRow: string

        string with log data to be logged.

      Returns Promise<number>

      The total number of log entries for this job so far.

    • Moves a job to the completed queue. Returned job to be used with Queue.prototype.nextJobFromJobData.

      Parameters

      • returnValue: ReturnType

        The jobs success message.

      • token: string

        Worker token used to acquire completed job.

      • fetchNext: boolean = true

        True when wanting to fetch the next job.

      Returns Promise<void | any[]>

      Returns the jobData of the next job in the waiting queue or void.

    • Moves the job to the delay set.

      Parameters

      • timestamp: number

        timestamp when the job should be moved back to "wait"

      • Optionaltoken: string

        token to check job is locked by current worker

      Returns Promise<void>

    • Moves a job to the failed queue.

      Type Parameters

      • E extends Error

      Parameters

      • err: E

        the jobs error message.

      • token: string

        token to check job is locked by current worker

      • fetchNext: boolean = false

        true when wanting to fetch the next job

      Returns Promise<void | any[]>

      Returns the jobData of the next job in the waiting queue or void.

    • Moves a job to the wait or prioritized state.

      Parameters

      • Optionaltoken: string

        Worker token used to acquire completed job.

      Returns Promise<number>

      Returns pttl.

    • Moves the job to the waiting-children set.

      Parameters

      • token: string

        Token to check job is locked by current worker

      • opts: MoveToWaitingChildrenOpts = {}

        The options bag for moving a job to waiting-children.

      Returns Promise<boolean>

      true if the job was moved

    • Promotes a delayed job so that it starts to be processed as soon as possible.

      Returns Promise<void>

    • Completely remove the job from the queue. Note, this call will throw an exception if the job is being processed when the call is performed.

      Parameters

      • opts: { removeChildren?: boolean } = {}

        Options to remove a job

      Returns Promise<void>

    • Removes child dependency from parent when child is not yet finished

      Returns Promise<boolean>

      True if the relationship existed and if it was removed.

    • Remove all children from this job that are not yet processed, in other words that are in any other state than completed, failed or active.

      Returns Promise<void>

      • Jobs with locks (most likely active) are ignored.
      • This method can be slow if the number of children is large (> 1000).
    • Attempts to retry the job. Only a job that has failed or completed can be retried.

      Parameters

      Returns Promise<void>

      If resolved and return code is 1, then the queue emits a waiting event otherwise the operation was not a success and throw the corresponding error. If the promise rejects, it indicates that the script failed to execute

    • Returns Omit<
          Job<DataType, ReturnType, NameType>,

              | "remove"
              | "prefix"
              | "toJSON"
              | "scripts"
              | "addJob"
              | "removeUnprocessedChildren"
              | "extendLock"
              | "updateData"
              | "updateProgress"
              | "removeChildDependency"
              | "getState"
              | "changeDelay"
              | "changePriority"
              | "moveToDelayed"
              | "moveToWaitingChildren"
              | "promote"
              | "discard"
              | "queue"
              | "asJSON"
              | "asJSONSandbox"
              | "log"
              | "clearLogs"
              | "moveToCompleted"
              | "moveToWait"
              | "moveToFailed"
              | "isCompleted"
              | "isFailed"
              | "isDelayed"
              | "isWaitingChildren"
              | "isActive"
              | "isWaiting"
              | "queueName"
              | "getChildrenValues"
              | "getIgnoredChildrenFailures"
              | "getFailedChildrenValues"
              | "getDependencies"
              | "getDependenciesCount"
              | "waitUntilFinished"
              | "retry",
      >

    • Returns a promise the resolves when the job has completed (containing the return value of the job), or rejects when the job has failed (containing the failedReason).

      Parameters

      • queueEvents: QueueEvents

        Instance of QueueEvents.

      • Optionalttl: number

        Time in milliseconds to wait for job to finish before timing out.

      Returns Promise<ReturnType>

    • addJobLog

      Parameters

      • queue: MinimalQueue

        A minimal queue instance

      • jobId: string

        Job id

      • logRow: string

        String with a row of log data to be logged

      • OptionalkeepLogs: number

        The optional amount of log entries to preserve

      Returns Promise<number>

      The total number of log entries for this job so far.

    • Creates a new job and adds it to the queue.

      Type Parameters

      • T = any
      • R = any
      • N extends string = string

      Parameters

      • queue: MinimalQueue

        the queue where to add the job.

      • name: N

        the name of the job.

      • data: T

        the payload of the job.

      • Optionalopts: JobsOptions

        the options bag for this job.

      Returns Promise<Job<T, R, N>>

    • Creates a bulk of jobs and adds them atomically to the given queue.

      Type Parameters

      • T = any
      • R = any
      • N extends string = string

      Parameters

      • queue: MinimalQueue

        the queue were to add the jobs.

      • jobs: { data: T; name: N; opts?: BulkJobOptions }[]

        an array of jobs to be added to the queue.

      Returns Promise<Job<T, R, N>[]>

    • Fetches a Job from the queue given the passed job id.

      Type Parameters

      • T = any
      • R = any
      • N extends string = string

      Parameters

      • queue: MinimalQueue

        the queue where the job belongs to.

      • jobId: string

        the job id.

      Returns Promise<Job<T, R, N>>

    • Instantiates a Job from a JobJsonRaw object (coming from a deserialized JSON object)

      Type Parameters

      • T = any
      • R = any
      • N extends string = string

      Parameters

      • queue: MinimalQueue

        the queue where the job belongs to.

      • json: JobJsonRaw

        the plain object containing the job.

      • OptionaljobId: string

        an optional job id (overrides the id coming from the JSON object)

      Returns Job<T, R, N>

    • Parameters

      • OptionalrawOpts: string
      • optsDecode: Record<string, string> = optsDecodeMap

      Returns JobsOptions