Class: JobQueue

JobQueue(numParallelopt, capacityopt)

A standard queue for jobs that can handle parallel jobs up to a specified degree of parallelism. This queue will run jobs whenever there is space on it (i.e. it cannot be paused/resumed). Emits the same events as Job using the class JobQueueEvent.

Constructor

new JobQueue(numParallelopt, capacityopt)

Parameters:
Name Type Attributes Default Description
numParallel Number <optional>
1 Optional. Defaults to 1.
capacity Number <optional>
Optional. The maximum capacity of this JobQueue. Only has an effect if the chosen policy is not set to ignore excess items. The maximum capacity is the total amount of Jobs either currently running or in the backlog this JobQueue can accomodate.
Optional. JobQueueCapacityPolicy | Number The policy to use when the maximum capacity is reached, and new items are being enqueued.
Author:
Source:

Extends

  • EventEmitter

Members

backlog :Number

Returns the amount of jobs on this queue that are waiting to be processed.
Type:
  • Number
Source:

currentJobs :ConstrainedQueue.<Job>

Type:
Source:

isBusy :Boolean

Returns true iff the queue is busy and all of its slots are currently used actively by jobs (the number of active jobs is equal to maximum degree of parallelism).
Type:
  • Boolean
Source:

isIdle :Boolean

Returns true if there are no jobs currently processing.
Type:
  • Boolean
Source:

isPaused :Boolean

Type:
  • Boolean
Source:

isWorking :Boolean

Returns true if there are any current jobs running.
Type:
  • Boolean
Source:

load :Number

Returns a number that represents the ratio between all current and enqueued jobs and this queue's parallelism. Numbers greater 1 indicate that there are jobs in the backlog. 0 Means the queue is idle and 1 means that it is using its full degree of parallelism and no jobs are waiting.
Type:
  • Number
Source:

numJobsDone :Number

Returns a value indicating how many Jobs have been done.
Type:
  • Number
Source:

numJobsFailed :Number

Returns a value indicating how many Jobs have failed.
Type:
  • Number
Source:

numJobsRunning :Number

Returns the amount of jobs currently running.
Type:
  • Number
Source:

observableDone :Observable.<JobQueueEvent>

Type:
Source:

observableFailed :Observable.<JobQueueEvent>

Type:
Source:

observableIdle :Observable.<JobQueueEvent>

Type:
Source:

observableRun :Observable.<JobQueueEvent>

Type:
Source:

queue :Queue.<Job>

Type:
Source:

utilization :Number

Returns a number indicating the queue's utilization in terms of a ratio of how many jobs are currently running and how many could be run. This number is therefore in the range [0, 1]. Unlike load, this property does not consider jobs in the backlog.
Type:
  • Number
Source:

workDone :Number

Returns a value indicating how much work has been done in terms of number of Jobs or their cost, depending on the queue's type.
Type:
  • Number
Source:

workFailed :Number

Returns a value indicating how much work has been failed in terms of number of Jobs or their cost, depending on the queue's type.
Type:
  • Number
Source:

Methods

addJob(job) → {this}

Add a Job to this Queue. Can either be an instance of Job or an async function.
Parameters:
Name Type Description
job Job.<T> | producerHandler.<Promise.<T>>
Source:
Returns:
Type
this

addJobs(…jobs) → {this}

Parameters:
Name Type Attributes Description
jobs Job.<T> | producerHandler.<Promise.<T>> <repeatable>
Source:
Returns:
Type
this

addSyncJob(job) → {this}

Parameters:
Name Type Description
job producerHandler.<T> A synchronous function to be used as a Job.
Source:
Returns:
Type
this

addSyncJobs(…jobs) → {this}

Parameters:
Name Type Attributes Description
jobs producerHandler.<T> <repeatable>
Many synchronous functions to add as Jobs.
Source:
Returns:
Type
this

clearBacklog() → {Array.<Job.<T>>}

Removes all jobs from the backlog and returns them.
Source:
Returns:
An array with all not yet run jobs.
Type
Array.<Job.<T>>

hasJob(job, eqCompareropt) → {Boolean}

Determines if a specific Job is on the backlog of this JobQueue.
Parameters:
Name Type Attributes Description
job Job.<T> The job to check for
eqComparer EqualityComparer.<Job.<T>> <optional>
Optional. A comparer to use for checking for equality. Defaults to the DefaultEqualityComparer which uses the identity operator.
Source:
Returns:
True, iff the Job is in the backlog.
Type
Boolean

isJobRunning(job, eqCompareropt) → {Boolean}

Determines if a specific Job is currently runnung on this JobQueue.
Parameters:
Name Type Attributes Description
job Job.<T> The Job to check for
eqComparer EqualityComparer.<Job.<T>> <optional>
Optional. A comparer to use for checking for equality. Defaults to the DefaultEqualityComparer which uses the identity operator.
Source:
Returns:
True, iff this JobQueue is currently processing the given job.
Type
Boolean

pause() → {this}

Pauses this queue, which results in no Jobs being further pushed on the internal processing queue. Note that already running jobs cannot be paused. If the queue is currently busy, you need to wait for the Idle- event by subscribing to the Observable.
Source:
See:
  • {symbolIdle}
  • {observableIdle}
Returns:
Type
this

removeJobFromBacklog(job, eqCompareropt) → {this}

Parameters:
Name Type Attributes Description
job Job.<T> The Job to remove from the backlog.
eqComparer EqualityComparer.<Job.<T>> <optional>
Optional. A comparer to use for checking for equality. Defaults to the DefaultEqualityComparer which uses the identity operator.
Source:
Returns:
Type
this

resume() → {this}

Un-pauses this queue and immediately checks for work that can be done.
Source:
Returns:
Type
this

runToCompletion() → {Promise.<void>}

Runs all jobs currently enqueued and then resolves when all are done. If the queue was paused, it will be resumed. Adding more jobs while this call is not resolved will defer it.
Source:
Returns:
That will resolve if the queue's current load is 0 (no jobs running and none in the backlog) or once it reaches 0 (if all currently enqueued jobs are done). The Promise is rejected if any of the jobs fails.
Type
Promise.<void>