Skip to content

cronox/cake-cron-jobs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status Latest Stable Version Downloads Latest Version License

Installation

Composer

composer require cronox/cake-cron-jobs

Load the Plugin

Ensure the Plugin is loaded in your config/bootstrap.php file

Plugin::load('Cronox/CronJobs');

Database

Init the database table by using cakephp's migrations

bin/cake migrations migrate --plugin Cronox/CronJobs

Example

To add method \App\Lib\Mailer::sendMail('cronox@example.com','Message text') to cron queue:

try {
    CronJobHelper::create(\App\Lib\Mailer::class, 'sendMail', ['cronox@example.com','Message text']);
} catch (\Exception $exception) {
    throw $exception;
}

To run queue by cron add following line to crontab:

bin/cake cronox/cron_jobs.cron_jobs

Example output:

➜  www ✗ bin/cake cronox/cron_jobs.cron_jobs
Found 1 jobs.
Running job #5 App\Lib\Mailer::sendMail
Job is completed correctly
➜  www ✗ 

Grouped tasks

try {
    $groupEmailCode = 'Email';
    $groupSMSCode = 'SMS';
    CronJobHelper::create(\App\Lib\Mailer::class, 'sendMail', ['cronox@example.com','Message text'], $groupEmailCode);
    CronJobHelper::create(\App\Lib\SmsApi::class, 'sendSMS', ['321654987','Message text'], $groupSMSCode);
} catch (\Exception $exception) {
    throw $exception;
}

To run grouped tasks by cron add following commands to crontab:

bin/cake cronox/cron_jobs.cron_jobs Email
bin/cake cronox/cron_jobs.cron_jobs SMS

About

CakePHP3 Plugin to create jobs for CRON

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages