egorspk / yii2-scheduler
Yii2 scheduler module
Installs: 321
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 3
Open Issues: 0
Type:yii2-extension
Requires
This package is auto-updated.
Last update: 2024-10-29 05:16:36 UTC
README
Cron task scheduler module for yii2. Features:
- Task management (creation, modification, deletion);
- Manually launch tasks or run tasks on a cron schedule;
- Tracking the results of tasks;
- Ajax user interface.
Installation
The preferred way to install this extension is through composer. Either run:
composer require egorspk/yii2-scheduler
or add
"egorspk/yii2-scheduler": "^1.0"
to the require section of your composer.json
file.
Subsequently, run
yii migrate/up --migrationPath=@vendor/egorspk/yii2-scheduler/migrations
in order to create the required tables in your database.
Usage
- Add this to your web and console configuration modules array:
'modules' => [
'scheduler' => [
'class' => 'spk\scheduler\Module'
],
...
],
- Next, add this line to your crontab file:
*/5 * * * * cd /project_path/; /php_path/php yii scheduler/run
Where:
- /project_path/ - path to your yii2 project (for example, /var/www/yii/);
- /php_path/ php - path to php (for example, /usr/bin/php).
Settings (web config)
- defaultFolder - path to the folder, where the methods of classes that can be used as a task (default value: @app/models);
- folderDepth - depth of class methods search by defaultFolder path (defaut value: 0).
Configuration example:
'modules' => [
'scheduler' => [
'class' => 'spk\scheduler\Module',
'defaultFolder' => __DIR__ . '/../models/scheduler',
'folderDepth' => 0
],
...
],
Tasks (methods)
The method must return a value of type bool. True - the task succeeded.
All calls echo statement will be written in the log of the task.
User interface
The user interface is divided into 3 tabs:
- Task list;
- Add/Edit task;
- Task execution log.
Note
-
img folder is needed only for README.md;
-
file scheduler.mwb - database project for the MySQL Workbench program.
License
MIT