$cronJobs
$cronJobs : array
Cron
Cron job management NOTE: The excellent library mtdowling/cron-expression (https://github.com/mtdowling/cron-expression) is required.
add(string $name, string $expression, \Liebig\Cron\Closure $function, bool $isEnabled)
Add a cron job
Expression definition:
* * * * * *
- - - - - -
| | | | | |
| | | | | + year [optional]
| | | | +----- day of week (0 - 7) (Sunday=0 or 7)
| | | +---------- month (1 - 12)
| | +--------------- day of month (1 - 31)
| +-------------------- hour (0 - 23)
+------------------------- min (0 - 59)
string | $name | The name for the cron job - has to be unique |
string | $expression | The cron job expression (e.g. for every minute: ' *') |
\Liebig\Cron\Closure | $function | The anonymous function which will be executed |
bool | $isEnabled | optional If the cron job should be enabled or disabled - the standard configuration is enabled |
if one of the parameters has the wrong data type, is incorrect or is not set
remove(string $name) : bool
Remove a cron job by name
string | $name | The name of the cron job which should be removed from execution |
Return true if a cron job with the given name was found and was successfully removed or return false if no job with the given name was found
run(bool $checkRundateOnce) : array
Run the cron jobs This method checks and runs all the defined cron jobs at the right time This method (route) should be called automatically by a server or service
bool | $checkRundateOnce | optional When we check if a cronjob is due do we take into account the time when the run function was called ($checkRundateOnce = true) or do we take into account the time when each individual cronjob is executed ($checkRundateOnce = false) - default value is true |
Return an array with the rundate, runtime, errors and a result cron job array (with name, function return value, runtime in seconds)
setLogOnlyErrorJobsToDatabase(bool $bool)
Enable or disable logging error jobs only to database NOTE: This works only if database logging is enabled
bool | $bool | Set to enable or disable logging error jobs only |
if the $bool function paramter is not a boolean
isLogOnlyErrorJobsToDatabase() : bool
Check if log error jobs to database only is enabled or disabled
if the cron::logOnlyErrorJobsToDatabase config value is not a boolean
Return boolean which indicates if logging only error jobs to database is enabled or disabled
setDeleteDatabaseEntriesAfter(int $hours)
Set the delete time of old database entries in hours
int | $hours | optional Set the delete time in hours, if this value is 0 the delete old database entries function will be disabled - default value is 0 |
if the $hours function paramter is not an integer
getDeleteDatabaseEntriesAfter() : int|null
Get the current delete time value in hours for old database entries
if the cron::deleteDatabaseEntriesAfter config value is not an integer or NULL
Return the current delete time value in hours or NULL if no value was set
setEnableJob(string $jobname, bool $enable) : bool
Enable a job by job name
string | $jobname | The name of the job which should be enabled |
bool | $enable | The trigger for enable (true) or disable (false) the job with the given name |
if the $enable function paramter is not a boolean
Return true if job was enabled successfully or false if no job with the $jobname parameter was found
saveJobsFromArrayToDatabase(array $jobArray, int $managerId)
Save cron jobs from an array to the database
array | $jobArray | This array holds all the ran cron jobs which should be logged to database - entry structure has to be job['name'], job['return'], job['runtime'] |
int | $managerId | The id of the saved manager database object which cares about the jobs |
log(string $level, string $message)
Log a message with the given level to Monolog logger if one is set and to Laravels build in Logger if it is enabled
string | $level | The logger level as string which can be debug, info, notice, warning, error, critival, alert, emergency |
string | $message | The message which will be logged to Monolog |
if the parameter $level or $message is not of the data type string or if the $level parameter does not match with debug, info, notice, warning, error, critival, alert or emergency