SiteDeactivateJob Class
Job to deactivate a site.
Constructor
SiteDeactivateJob
()
Item Index
Methods
- createCommandTask
- doPersistenceTasks
- getChunkOfWorkPercentage
- getId
- getInitiatorTasks
- getSite
- getTasks
- getWorkerTasks
- init
- log
- onBeforeFirstTask
- onCompleted
- onStart
- onUpdate
- processClusterResults
- processResults
- processWorkerResults
- run
- setChunkOfWorkPercentage
- setParallelLimit
- setRunAsInitiator
- setSite
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:
-
type
StringThe command type -
command
ObjectThe command to broadcast to the cluster.
doPersistenceTasks
(
-
cb
Update site to active as false in database to deactivate.
Parameters:
-
cb
Function- callback
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
Get tasks to deactivate a site.
Parameters:
-
cb
Function- callback function
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
FunctionA callback that takes two parameters: cb(Error, Object|Array)
getWorkerTasks
(
-
cb
Get task to stop accepting traffic for the site.
Parameters:
-
cb
Function- callback
init
(
-
[name]
-
[jobId]
The initialization function sets the job's name and ID as well as provide an
instace of DAO.
Parameters:
-
[name]
String optionalThe job's name -
[jobId]
String optionalThe 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
StringThe 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
FunctionA 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 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. -
err
ErrorThe 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 optionalThe 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
ErrorThe error that occurred (if any) during task execution -
results
ArrayAn array containing the result of each executed task -
cb
FunctionA 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
ErrorThe error that occurred (if any) during task execution -
results
ArrayAn array containing the result of each executed task -
cb
FunctionA 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
(
JobRunner
-
chunkOfWorkPercentage
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
IntegerThe maximum number of tasks to run in parallel
setRunAsInitiator
(
ClusterJobRunner
-
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:
-
isInitiator
Boolean
Returns:
ClusterJobRunner:
This instance
setSite
(
Object
-
options
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
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).