API Docs for: 0.8.0
Show:

AsyncJobRunner Class

An abstract implementation of JobRunner that handles performing a series of asynchronous tasks. The runner provides the ability to run the tasks in parallel or 1 after another. The extending implementation must provides the set of tasks to execute

Constructor

AsyncJobRunner

()

Methods

getChunkOfWorkPercentage

() Number
Retrieves the chunk of work percentage

Returns:

Number:

getId

() String
Retrieves the unique identifier for the job

Returns:

String: The job ID

getTasks

(
  • cb
)

Responsible for providing an array or hash of tasks that will be executed by the job. The extending implmentation MUST override this function or an error will be thrown.

Parameters:

  • cb Function

    A callback that takes two parameters: cb(Error, Object|Array)

init

(
  • [name]
  • [jobId]
)
The initialization function sets the job's name and ID as well as provide an instace of DAO.

Parameters:

  • [name] String optional
    The job's name
  • [jobId] String optional
    The job's unique identifier

log

(
  • message
)
Logs a message to the system logger as well as to the persistence layer. The function takes a variable number of arguments. A string message/pattern followed by the variables to fill in with that data. See util.format or the implementation for Winston loggers.

Parameters:

  • message String
    The message or pattern to log

onBeforeFirstTask

(
  • cb
)

Called directly before the first tasks begins to execute. It is recommended that the extending implementation override this function in order to call the "onStart" function.

Parameters:

  • cb Function

    A callback that takes one optional error parameter

onCompleted

(
  • [status]
  • err
)
Called once by the extending implementation when the job has completed execution whether that be successful completion or by error.

Parameters:

  • [status] String optional
    The final status of the job. If not provided the status will default to 'COMPLETED' or 'ERRORED' when an error is provided as the second parameter.
  • err Error
    The error, if any, that was generated by the job's execution

onStart

(
  • [status='RUNNING']
)
To be called once by the extending implmentation to mark the start of the job. The function persists the job record and makes it available to future calls to onUpdate or onComplete.

Parameters:

  • [status='RUNNING'] String optional
    The starting status of the job

onUpdate

(
  • progressIncrement
  • [status]
)
To be called by the extending implmentation when progress has been made. The incremental amount of progress should be provided keeping in mind that the overall progress should not exceed 100. Optionally, the status parameter may also be included.

Parameters:

  • progressIncrement Integer
  • [status] String optional

processResults

(
  • err
  • results
)

Called once after job execution. It is recommended that extending implmentations use this function to peform any ETL operations to prepare data for the callback.

Parameters:

  • err Error

    The error generated during task execution if exists

  • results Object | Array

    The result of each tasks' execution.

run

(
  • cb
)

Kicks off the set of tasks for the job. The implementation wraps the items in a domain in an attempt to provide a level of error handling. When a qualifying error is intercepted by the domain processResults is called providing the error and all other task execution is halted.

Parameters:

  • cb Function

setChunkOfWorkPercentage

(
  • chunkOfWorkPercentage
)
JobRunner
Sets the portion of the over arching job that this job instance will contribute once complete.

Parameters:

  • chunkOfWorkPercentage Number

Returns:

setParallelLimit

(
  • max
)

Sets the number of tasks to run in parallel

Parameters:

  • max Integer

    The maximum number of tasks to run in parallel

Properties

dao

DAO
An instace of DAO to provide direct access to the DB if it is needed.

id

String
Holds the unique identifier for the job

parallelLimit

Integer

The number of tasks to run in parallel

taskFactor

Number
The percentage of the overall work that this job accounts for. If this job is run by itself then the value should be 1. This means that 100% of the job is completed by this job. If, for example, the value is .333 then it is assumed that this job accounts for 33% or one third of the over all work necessary to complete the job. This is handy when a large job is made up of smaller jobs. This value will assist in allowing the jobs to calculate their update increments. The number must be a value between 0 (exclusive) & 1 (inclusive).