ClusterJobRunner Class
Abstract prototype used to run a job against an entire cluster by running in one of two modes: initiator and worker.
Constructor
ClusterJobRunner
()
Item Index
Methods
Properties
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:
-
typeStringThe command type
-
commandObjectThe command to broadcast to the cluster.
getChunkOfWorkPercentage
()
Number
Returns:
getId
()
String
Returns:
getInitiatorTasks
-
cb
Retrieves the tasks needed to contact each process in the cluster to perform the job.
Parameters:
-
cbFunctionA callback that takes two parameters: cb(Error, Object|Array)
getTasks
-
cb
Retrieves the tasks to be executed by this job. The tasks provided to the callback are determined by the isInitiator property.
Parameters:
-
cbFunctionA callback that takes two parameters: cb(Error, Object|Array)
getWorkerTasks
-
cb
Retrieves the tasks needed to perform the job on this process.
Parameters:
-
cbFunctionA callback that takes two parameters: cb(Error, Object|Array)
init
-
[name] -
[jobId]
Parameters:
-
[name]String optionalThe job's name -
[jobId]String optionalThe job's unique identifier
log
-
message
Parameters:
-
messageStringThe 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:
-
cbFunctionA 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
Parameters:
-
[status]String optionalThe 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. -
errErrorThe error, if any, that was generated by the job's execution
onStart
-
[status='RUNNING']
Parameters:
-
[status='RUNNING']String optionalThe starting status of the job
onUpdate
-
progressIncrement -
[status]
Parameters:
-
progressIncrementInteger -
[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:
-
errErrorThe error that occurred (if any) during task execution
-
resultsArrayAn array containing the result of each executed task
-
cbFunctionA callback that provides two parameters: The first is any error that occurred (if exists) and the second is an object that encloses the properties that describe the job as well as the raw results.
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:
-
errErrorThe error that occurred (if any) during task execution
-
resultsArrayAn array containing the result of each executed task
-
cbFunctionA 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:
-
errErrorThe error that occurred (if any) during task execution
-
resultsArrayAn array containing the result of each executed task
-
cbFunctionA 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:
-
cbFunction
setChunkOfWorkPercentage
-
chunkOfWorkPercentage
Parameters:
-
chunkOfWorkPercentageNumber
Returns:
setParallelLimit
-
max
Sets the number of tasks to run in parallel
Parameters:
-
maxIntegerThe maximum number of tasks to run in parallel
setRunAsInitiator
-
isInitiator
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:
-
isInitiatorBoolean
Returns:
This instance
Properties
id
String
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
