See also: Writing Registry Plugins
Some additional conventions are required when writing a Job Plugin.
- The name of the Plugin should match the format
FooJob
. The prefix (eg:Foo
) will be used as thejob_type
in cm_co_jobs. - The Plugin must implement two functions, which are defined in
Model/FooJob.php
.execute($coId, $CoJob, $params)
, which will be passed the relevant CO ID, a CoJob object, and an (optional) array of parameters in accordance with the Plugin's configuration.- When the Job is started, it should call
$CoJob->update()
(with appropriate arguments). - When executing, the Job should not typically generate output, but should instead create Job History records. If it is absolutely necessary to write to stdout, the Job should follow Cake's Console output levels.
- If the Job loops over multiple records, it should check
$CoJob->canceled($jobid)
after each iteration, and immediately terminate processing if the Job has been canceled. - When complete, the Job must call
$CoJob->finish()
, with appropriate arguments. (The Job will be set to started when dispatched, before the Plugin is invoked.)
- When the Job is started, it should call
parameterFormat()
, which returns an array of parameters supported by the plugin. Each entry in the array has a key of the parameter name and a value of an array with the following keys:choices
: An array of permitted values for the parameter (whentype
isselect
)help
: Help text for the parameterrequired
: Boolean indicating whether or not this parameter is requiredtype
: One ofint
,select
, orstring
.