API Docs for: 0.8.0
Show:

SiteJobRunner Class

Setup for running site activation job.

Constructor

Methods

createCommandTask

(
  • type
  • command
)
Creates a simple task that sends a command to the entire cluster then waits for all responses. Success if determined by the lack of an Error in the callback in addition to the lack of an "error" property on each item in the results array provided by the cb from the call to send the command.

Parameters:

  • type String
    The command type
  • command Object
    The command to broadcast to the cluster.

getChunkOfWorkPercentage

() Number
Retrieves the chunk of work percentage

Returns:

Number:

getId

() String
Retrieves the unique identifier for the job

Returns:

String: The job ID

getInitiatorTasks

(
  • cb
)
Retrieves the tasks needed to contact each process in the cluster to perform the job.

Parameters:

  • cb Function

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

getSite

() Object

Get the current site of this instance of SiteJobRunner.

Returns:

Object:

the site object

getTasks

(
  • cb
)
Retrieves the tasks to be executed by this job. The tasks provided to the callback are determined by the isInitiator property.

Parameters:

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

getWorkerTasks

(
  • cb
)
Retrieves the tasks needed to perform the job on this process.

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 before the start of task execution. When the property isInitiator = TRUE the onStart function is called to mark the start of the job. It is not called for others because it is assumed that workers are already part of an in-progress cluster job and that an existing job id has been provided.

Parameters:

  • cb Function
    A callback that takes two parameters. The first is an Error (if occurred) and the second is a boolean value that indicates if the function successfully completed any pre-requsite operations before task execution begins.

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

processClusterResults

(
  • err
  • results
  • cb
)

Called when the tasks have completed execution and isInitiator = FALSE. The function ispects the results of each processes' execution and attempts to decipher if an error occurred. The function calls back with a result object that provides four properties: success (Boolean), id (String), pluginUid (String), results (Array of raw results).

Parameters:

  • err Error
    • error in the process or null
  • results Array
    • array of results from the tasks run
  • cb Function
    • callback function

processResults

(
  • err
  • results
  • cb
)
Called when the job has completed its assigned set of tasks. The function is responsible for processing the results and calling back with the refined result.

Parameters:

  • err Error
    The error that occurred (if any) during task execution
  • results Array
    An array containing the result of each executed task
  • cb Function
    A callback that provides two parameters: The first is any error that occurred (if exists) and the second is dependent on the isInitiator property. See processClusterResults and processWorkerResults for more details.

processWorkerResults

(
  • err
  • results
  • cb
)
Called when the tasks have completed execution and isInitiator = FALSE. The function blindly passes the results of the tasks back to the callback.

Parameters:

  • err Error
    The error that occurred (if any) during task execution
  • results Array
    An array containing the result of each executed task
  • cb Function
    A callback that provides two parameters: The first is any error that occurred (if exists) and the second is an array of Boolean values that indicate the success or failure of each task.

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

setRunAsInitiator

(
  • isInitiator
)
ClusterJobRunner
Indicates if the job is to run as the initiator or a worker. When TRUE, the job sends commands to all processes in the cluster to perform the job. When FALSE, the actual job is performed on this process.

Parameters:

  • isInitiator Boolean

Returns:

ClusterJobRunner: This instance

setSite

(
  • options
)
Object

Set the site for an instance of SiteJobRunner.

Parameters:

  • options Object
    • uid String
      • site unique id
    • hostname String
      • result of site hostname edit/create
    • displayName String
      • result of site display name edit/create

Returns:

Object:

the instance in which the site was set.

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

isInitiator

Boolean
Indicates if the job is to run as the initiator or a worker. When TRUE, the job sends commands to all processes in the cluster to perform the job. When FALSE, the actual job is performed.

parallelLimit

Integer
The number of tasks to run in parallel

site

String - default to empty string

The site for this instance of SiteJobRunner

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).