Options
All
  • Public
  • Public/Protected
  • All
Menu

Manages a set of jobs that have to be run.

Hierarchy

  • HeapJobOrderer

Implements

Index

Constructors

constructor

  • Create the JobOrderer and inform it of the jobs to manage.

    throws

    When one of the jobs has a prerequisite that is not one of the jobs, or is itself.

    Parameters

    • rootJobs: Set<Job>

    Returns HeapJobOrderer

Properties

Private Readonly inProgress

inProgress: Set<Job> = ...

Holds all source Jobs that have been requested via popNextJob but haven't yet been reported completed via reportCompletedJob.

Private Readonly jobToDependents

jobToDependents: Map<Job, Set<Job>> = ...

Maps each Job to its dependents. Used to update dependency graph.

Job B's dependents include Job A if and only if Job A's prerequisites include Job B.

Private Readonly jobToNumCompletedPrereqs

jobToNumCompletedPrereqs: Map<Job, number> = ...

Maps each Job to the number of its completed prerequisites (how many of its prerequisite Jobs have been reported completed).

If the number of a Job's prerequisites is equal to the number of its completed prerequisites, then all of its prerequisites are completed and it's ready to be run.

Private Readonly nonSources

nonSources: Set<Job> = ...

Holds all Jobs that aren't sources.

Private Readonly sources

sources: Heap<Job> = ...

Holds all Jobs that are sources, meaning that they are runnable because they have no uncompleted prerequisistes.

It's a Heap instead of a Set because we want to choose the source with the most dependents as the next Job to run. The sorting function prioritizes Jobs by the number of dependents they have.

Methods

isDone

  • isDone(): boolean
  • Returns boolean

    Whether all of the jobs are complete.

Private jobIsSource

  • jobIsSource(job: Job): boolean
  • Checks whether the given job is a source.

    A job is a source if all of its prerequisites are completed.

    Parameters

    • job: Job

      The job to check.

    Returns boolean

    Whether the given job is a source.

popNextJob

  • popNextJob(): null | Job
  • Chooses the next job to run and returns it. Marks that job as in-progress. If there is no job that can be run, returns null.

    Returns null | Job

    The next job to run.

reportCompletedJob

  • reportCompletedJob(completedJob: Job): void
  • Marks a job as completed. JobOrderer will update the dependency graph and then forget about this job.

    Parameters

    • completedJob: Job

      The job that is completed.

    Returns void

reportFailedJob

  • reportFailedJob(failedJob: Job): void
  • Marks an in-progress job as failed. JobOrderer will try to run it again at some point.

    Parameters

    • failedJob: Job

      The job that failed.

    Returns void

Generated using TypeDoc