Class \Prado\Util\Cron\TCronModule
TCronModule runs time based services for the application. This will run a task at a given time. A task can be a task class or a module Id followed by '->' followed by a method with or without parameters. eg.
<module id="cron" class="Prado\Util\Cron\TCronModule" DefaultUserName="admin">
<job Name="cronclean" Schedule="0 0 1 * * *" Task="Prado\Util\Cron\TDbCronCleanLogTask" UserName="cron" />
<job Name="dbcacheclean" Schedule="* * * * *" Task="dbcache->flushCacheExpired(true)" />
<job Schedule="0 * * * *" Task="mymoduleid->taskmethod" />
</module>
The schedule is formatted like a linux crontab schedule expression. TTimeSchedule parses the schedule and supports 8 different languages. Advanced options, like @daily, and @hourly, are supported.
This module is designed to be run as a system Crontab prado-cli every minute. The application then decides what tasks to execute, or not, and when.
The following is an example for your system cron tab to run the PRADO application cron.
* * * * * php /dir_to_/vendor/bin/prado-cli app /dir_to_app/ cron
The default cron user can be set with set$DefaultUserName with its default being 'cron' user. The default user is used when no task specific user is specifiedThe 'cron' user should exist in the TUserManager to switched the application user properly.
Class hierarchy
- \Prado\Util\Cron\TCronModule implements IPermissions
- \Prado\TModule implements IModule
- \Prado\TApplicationComponent
- \Prado\TComponent
Since: 4.2.0
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
getRawTasks() : array<string|int, array<string|int, mixed>>|array<string|int, TCronTask>
These are the tasks specified in the configuration and getAdditionalCronTasks
until {@see ensureTasks} is called.
|
public
|
|
public
|
|
public
|
getTaskInfos([bool $forceupdate = false ]) : array<string|int, TCronTaskInfo>
Objects should handle fxGetCronTasks($sender, $param)
|
public
|
|
public
|
|
public
|
|
public
|
init(array<string|int, mixed>|TXmlElement $config) : mixed
Initializes the module. Read the configuration, installs Shell Actions,
should Request cron be activated.
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
setAdditionalCronTasks(null|array<string|int, mixed>|string $tasks) : mixed
This will take a string that is an array of tasks that has been
through serialize(), or json_encode, or is an xml file of additional tasks.
If one task is set, then it is automatically placed into an array. |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
validateTask(array<string|int, mixed> $properties) : mixed
Validates that schedule and task are present.
Subclasses overload this method to add their own validation. |
protected
|
ensureTasks() : array<string|int, TCronTask>
makes the tasks from the configuration array into task objects.
|
protected
|
|
protected
|
|
protected
|
logCronTask(TCronTask $task, string $username) : mixed
Logs the cron task being run with the system log and output on cli
|
protected
|
|
protected
|
readConfiguration(array<string|int, mixed>|TXmlElement $config) : mixed
This reads the configuration and stores the specified tasks, for lazy loading, until needed.
|
protected
|
setPersistentData(string $name, TCronTask $task) : bool
when instancing and then loading the tasks, this sets the persisting data of
the task from the global state. When there is no instance in the global state,
the lastExecTime is initialized.
|
protected
|
updateTaskInfo(TCronTask $task) : mixed
sets the lastExecTime to now and increments the processCount. This saves
the new data to the global state.
|
public
mixed
|
DEFAULT_CRON_USER
The name of the cron user
|
'cron'
|
public
mixed
|
LAST_CRON_TIME
Key to global state of the last time SystemCron was run
|
'prado:cron:lastcron'
|
public
mixed
|
METHOD_SEPARATOR
The separator for TCronMethodTask
|
'->'
|
public
mixed
|
NAME_KEY
|
'name'
|
public
mixed
|
PERM_CRON_SHELL
The permission for the cron shell
|
'cron_shell'
|
public
mixed
|
SCHEDULE_KEY
|
'schedule'
|
public
mixed
|
SHELL_LOG_BEHAVIOR
The behavior name for the Shell Log behavior
|
'shellLog'
|
public
mixed
|
TASK_KEY
|
'task'
|
public
mixed
|
TASKS_INFO
Key to global state of each task, lastExecTime and ProcessCount
|
'prado:cron:tasksinfo'
|
public
mixed
|
USERNAME_KEY
|
'username'
|
\Prado\TApplicationComponent::FX_CACHE_FILE, \Prado\TComponent::GLOBAL_RAISE_EVENT_LISTENER |