Download the PHP package thamtech/yii2-scheduler without Composer
On this page you can find all versions of the php package thamtech/yii2-scheduler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2-scheduler
Yii2 Scheduler
A configuration-driven scheduled task manager for Yii2.
This is adapted from webtoolsnz/yii2-scheduler to provide a more configuration-driven approach.
The main differences:
- webtoolsnz/yii2-scheduler
- automatically picks up Task classes in the
@app/tasks
folder - once tasks have been established in the database table, the
active
value from the database controls whether the task is enabled, not theactive
property in the Task class
- automatically picks up Task classes in the
- thamtech/yii2-scheduler
- tasks are defined explicitly as part of the scheduler module config
- the
active
property of the Task instance controls whether the task is enabled (so that it may be controlled programmatically instead of only via the scheduler's databse table)
Installation
The preferred way to install this extension is through composer.
Install using the following command.
Now that the package has been installed you need to configure the module in your application.
The config/console.php
file (or the equivalent console config file if you are
using a different Yii project template) should be updated to reflect the changes
below:
also add this to the top of your config/console.php
file:
Run the database migrations, which will create the necessary tables:
To implement the GUI for reviewing scheduled tasks and logs, add a web controller:
Example Task
You can now create your first task using scheduler. In this example, we will
create ConcatStringsTask.php
inside the tasks
directory of your app:
In your scheduler
module config within your console app, define the task:
The above code defines a simple task that runs at the start of every hour, and
prints "Hello World". An alternative approach would be to hard-code some or all
of the properties in your task class (like schedule
). However, this example
is more in line with the project's goal of being a more configuration-driven
approach to defining tasks.
The $schedule
property of this class defines how often the task will run,
these are simply Cron Expression
You can define multiple task instances in the scheduler
module config, and it
is ok to reuse the same Task class for multiple instances. Here is an example
with an additional "Foo Bar" task that runs every hour on the half-hour:
Running the tasks
Scheduler provides an intuitive CLI for executing tasks, below are some examples
In order to have your tasks run automatically simply setup a crontab like so
Events & Errors
Events are thrown before and running individual tasks as well as at a global level for multiple tasks
Task Level
or at the global level, to throw errors in /yii
You could throw the exceptions at the task level, however this will prevent further tasks from running.
License
The MIT License (MIT). Please see LICENSE.md for more information.
All versions of yii2-scheduler with dependencies
dragonmantank/cron-expression Version ~1.2 || ~2.0 || ~3.0