Properties

$cronJobs

$cronJobs : array

Type

array — Saves all the cron jobs

$logger

$logger : \Monolog\Logger

Type

\Monolog\Logger — Logger object Monolog logger object if logging is wished or null if nothing should be logged to this logger

Methods

add()

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)

Parameters

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

Throws

\InvalidArgumentException

if one of the parameters has the wrong data type, is incorrect or is not set

remove()

remove(string $name) : bool

Remove a cron job by name

Parameters

string $name

The name of the cron job which should be removed from execution

Returns

bool —

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()

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

Parameters

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

Returns

array —

Return an array with the rundate, runtime, errors and a result cron job array (with name, function return value, runtime in seconds)

setLogger()

setLogger(\Monolog\Logger $logger)

Add a custom Monolog logger object

Parameters

\Monolog\Logger $logger

optional The Monolog logger object which will be used for cron logging, if this parameter is null the logger will be removed - default value is null

getLogger()

getLogger() : \Monolog\Logger|null

Get the Monolog logger object

Returns

\Monolog\Logger|null —

Return the set logger object or null if no logger is set

setLaravelLogging()

setLaravelLogging(bool $bool)

Enable or disable Laravels build in logging

Parameters

bool $bool

Set to enable or disable Laravels logging

Throws

\InvalidArgumentException

if the $bool function paramter is not a boolean

isLaravelLogging()

isLaravelLogging() : bool

Is Laravels build in logging enabled or disabled

Throws

\UnexpectedValueException

if the cron::laravelLogging config value is not a boolean or NULL

Returns

bool —

Return boolean which indicates if Laravels logging is enabled or disabled

setDatabaseLogging()

setDatabaseLogging(bool $bool)

Enable or disable database logging

Parameters

bool $bool

Set to enable or disable database logging

Throws

\InvalidArgumentException

if the $bool function paramter is not a boolean

isDatabaseLogging()

isDatabaseLogging() : boolean

Is logging to database enabled or disabled

Throws

\UnexpectedValueException

if the cron::databaseLogging config value is not a boolean

Returns

boolean —

Return boolean which indicates if database logging is enabled or disabled

setLogOnlyErrorJobsToDatabase()

setLogOnlyErrorJobsToDatabase(bool $bool)

Enable or disable logging error jobs only to database NOTE: This works only if database logging is enabled

Parameters

bool $bool

Set to enable or disable logging error jobs only

Throws

\InvalidArgumentException

if the $bool function paramter is not a boolean

isLogOnlyErrorJobsToDatabase()

isLogOnlyErrorJobsToDatabase() : bool

Check if log error jobs to database only is enabled or disabled

Throws

\UnexpectedValueException

if the cron::logOnlyErrorJobsToDatabase config value is not a boolean

Returns

bool —

Return boolean which indicates if logging only error jobs to database is enabled or disabled

reset()

reset()

Reset the Cron class Remove the cron jobs array and the logger object

setRunInterval()

setRunInterval(int $minutes)

Set the run interval - the run interval is the time between two cron job route calls

Parameters

int $minutes

Set the interval in minutes

Throws

\InvalidArgumentException

if the $minutes function paramter is not an integer

getRunInterval()

getRunInterval() : int|null

Get the current run interval value

Throws

\UnexpectedValueException

if the cron::runInterval config value is not an integer or NULL

Returns

int|null —

Return the current interval value in minutes or NULL if there is no value set

setDeleteDatabaseEntriesAfter()

setDeleteDatabaseEntriesAfter(int $hours)

Set the delete time of old database entries in hours

Parameters

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

Throws

\InvalidArgumentException

if the $hours function paramter is not an integer

getDeleteDatabaseEntriesAfter()

getDeleteDatabaseEntriesAfter() : int|null

Get the current delete time value in hours for old database entries

Throws

\UnexpectedValueException

if the cron::deleteDatabaseEntriesAfter config value is not an integer or NULL

Returns

int|null —

Return the current delete time value in hours or NULL if no value was set

setEnableJob()

setEnableJob(string $jobname, bool $enable) : bool

Enable a job by job name

Parameters

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

Throws

\InvalidArgumentException

if the $enable function paramter is not a boolean

Returns

bool —

Return true if job was enabled successfully or false if no job with the $jobname parameter was found

setDisableJob()

setDisableJob(String $jobname) : bool

Disable a job by job name

Parameters

String $jobname

The name of the job which should be disabled

Returns

bool —

Return true if job was disabled successfully or false if no job with the $jobname parameter was found

isJobEnabled()

isJobEnabled(String $jobname) : bool|null

Is the given job by name enabled or disabled

Parameters

String $jobname

The name of the job which should be checked

Returns

bool|null —

Return boolean if job is enabled (true) or disabled (false) or null if no job with the given name is found

setEnablePreventOverlapping()

setEnablePreventOverlapping()

Enable prevent job overlapping

setDisablePreventOverlapping()

setDisablePreventOverlapping()

Disable prevent job overlapping

isPreventOverlapping()

isPreventOverlapping() : bool

Is prevent job overlapping enabled or disabled

Returns

bool —

Return boolean if prevent job overlapping is enabled (true) or disabled (false)

setEnableInTimeCheck()

setEnableInTimeCheck()

Enable the Cron run in time check

setDisableInTimeCheck()

setDisableInTimeCheck()

Disable the Cron run in time check

isInTimeCheck()

isInTimeCheck() : bool

Is the Cron run in time check enabled or disabled

Returns

bool —

Return boolean if the Cron run in time check is enabled (true) or disabled (false)

getCronJobs()

getCronJobs() : array

Get added Cron jobs as array

Returns

array —

Return array of the added Cron jobs

saveJobsFromArrayToDatabase()

saveJobsFromArrayToDatabase(array $jobArray, int $managerId)

Save cron jobs from an array to the database

Parameters

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()

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

Parameters

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

Throws

\InvalidArgumentException

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

deleteOldDatabaseEntries()

deleteOldDatabaseEntries() : bool

Delete old manager and job entries

Returns

bool —

Return true if the database is cleaned of old entries or false if the database was not cleaned successfully