JobRunner Class
A base interface that system jobs can implement. The premise is that every job will have an ID and a name. The job is initialized by calling the "init" function and started by calling the "run" function. The specific implementation is also provided with functions to report the start, update, and end of the job run. The advantage to extending this prototype is that the provided functions allow for creating a persisted record of the job. In addition, log statements generated by the job are also persisted (as long as the provided "log" function is called).
Constructor
JobRunner
()
Item Index
Methods
Properties
- dao
- DEFAULT_DONE_STATUS static
- DEFAULT_ERROR_STATUS static
- DEFAULT_START_STATUS static
- id
- JOB_LOG_STORE_NAME static
- JOB_STORE_NAME static
- taskFactor
Methods
getChunkOfWorkPercentage
()
Number
Retrieves the chunk of work percentage
Returns:
getId
()
String
Retrieves the unique identifier for the job
Returns:
The job ID
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
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
run
-
cb
Call this function once to start the job. The job will execute the callback upon completion.
Parameters:
-
cb
FunctionA callback that provides two parameters: The first is any error that was generated and the second is the implementation specific result of the job.
Properties
DEFAULT_DONE_STATUS
String
private
static
The status code for a job that has completed successfully
DEFAULT_ERROR_STATUS
String
private
static
The status code for a job that has generated a fatal error
DEFAULT_START_STATUS
String
private
static
The status code for a job that is in progress
id
String
Holds the unique identifier for the job
JOB_LOG_STORE_NAME
String
private
static
The name of the persistence entity that contains the log statements for the job
JOB_STORE_NAME
String
private
static
The name of the persistence entity that contains the job descriptor
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).