A simple module to have cron-like jobs in your database. In addition to yii's commands, yii-job can be used to create on-the-fly asynchronous jobs. Different kinds of jobs are supported:
- Jobs with crontab that are triggered at defined times.
- Ad-Hoc jobs that are executed at a defined time (or as soon as possible).
To actually process the jobs you can use the JobCommand, which itself can be triggered by a sytem cron job. A common scenario is system a cron job that is executed once per minute to trigger JobCommand.
Import data/mysql.sql into your database.
In your config add the module:
'modules' => array(
'yii-job' => array(
),
),
In your config add the JobManager component:
'components'=>array(
'jobManager' => array(
'class' => 'application.modules.yii-job.components.JobManager',
'jobs' => array(
array(
'class' => 'MyJob', //this is your own class that extends application.modules.yii-job.models.Job
'crontab' => '* 3 * * *'
)
)
),
),
Optional: add module models import for convenicence
'import'=>array(
'application.modules.yii-job.models.*'
),
In your console config import the JobCommand
'commandMap' => array(
'job' => 'application.modules.yii-job.commands.JobCommand'
),
If you want to trigger the job processing from the command line you still need a cron job that executes the JobCommand. It should be triggers like this:
yiic job
This is the index command which will sync your jobs in the config with your database and run all jobs that are due.
Thanks to mtdowling for providing a nice php crontab parser: https://github.com/mtdowling/cron-expression