2017 © Pedro Peláez
 

library scheduler

image

crabstudio/scheduler

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 15 Forks
  • 0 Open issues
  • 14 Versions
  • 0 % Grown

The README.md

Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

# CakePHP 3: Scheduler Plugin

Makes scheduling tasks in CakePHP much simpler., (*2)

Author

Trent Richardson [http://trentrichardson.com], (*3)

Contributor

Anh Tuan Nguyen [anhtuank7c@hotmail.com], (*4)

License

Copyright 2015 Trent Richardson, (*5)

You may use this project under MIT license. http://trentrichardson.com/Impromptu/MIT-LICENSE.txt, (*6)

How It Works

SchedulerShell works by scheduling one cron (SchedulerShell) for your project. Then in bootstrap.php you can create intervals for all your tasks. Deploying new scheduled tasks are now much easier; one crontab entry executes all your tasks., (*7)

Install

You can install this plugin into your CakePHP application using composer., (*8)

The recommended way to install composer packages is:, (*9)

composer require crabstudio/scheduler

Or add the following lines to your application's composer.json:, (*10)

"require": {
    "crabstudio/scheduler": "^1.0"
}

followed by the command:, (*11)

composer update

Load plugin

Open terminal/command line then enter following command:, (*12)

bin/cake plugin load Scheduler

Or add this line to Your_project\config\bootstrap.php, (*13)

Plugin::load('Scheduler');

Schedule a single system cron by the shortest interval you need for SchedulerShell.php. For example, if you have 5 tasks and the most often run is every 5 minutes, then schedule this cron to run at least every 5 minutes. For more help see Shells as Cron Jobs., (*14)

Example cron job:, (*15)

*/5 * * * * cd /path/to/app && bin/cake Scheduler.Scheduler

This would run the SchedulerShell every 5 minutes., (*16)

Now once this shell is scheduled we are able to add our entries to bootstrap.php. Lets say we want to schedule a CleanUp task daily at 5am and a NewsletterTask for every 15 minutes., (*17)

Configure::write('SchedulerShell.jobs', array(
    'task_01' => array('interval' => 'next day 5:00', 'task' => 'EmailQueue'),// tomorrow at 5am
    'task_02' => array('interval' => 'PT15M', 'task' => 'Newsletter') //every 15 minutes
));

DateInterval

`PT1S` task will run each 1 Second
`PT1M` task will run each 1 Minute
`PT1H` task will run each 1 Hour
`P1D` task will run each 1 Day
`P1W` task will run each 1 Week
`P1M` task will run each 1 Month
`P1Y` task will run each 1 Year

datetime.formats.relative

`next day 05:00` task will on tomorrow at 05:00
`sunday 05:00` task will on sunday at 05:00
`weekday 05:00` task will on from Mon-Friday at 05:00
`saturday 05:00` task will on Saturday at 05:00
`sun 05:00` task will on Sun at 05:00
`sun 05:00 next month` task will on Sun at 05:00 in next month
`Monday next week 2020-01-01` task will on Monday in next week 2020-01-01

The key to each entry will be used to store the previous run. These must be unique!, (*18)

interval is set one of two ways. 1) For set times of day we use PHP's relative time formats: "next day 5:00"., (*19)

2) To use an interval to achieve "every 15 minutes" we use DateInterval string format: "PT15M"., (*20)

task is simply the name of the Task., (*21)

There are a couple optional arguments you may pass: "action" and "pass"., (*22)

action defaults to "execute", which is the method name to call in the task you specify., (*23)

pass defaults to array(), which is the array of arguments to pass to your "action"., (*24)

Configure::write('SchedulerShell.jobs', array(
    'CleanUp' => array('interval' => 'next day 5:00', 'task' => 'CleanUp', 'action' => 'execute', 'pass' => array()),
    'Newsletters' => array('interval' => 'PT15M', 'task' => 'Newsletter', 'action' => 'execute', 'pass' => array())
));

Storage of Results

SchedulerShell keeps track of each run in a json file. By default this is stored in TMP and is named "cron_scheduler.json"., (*25)

If you need to change either of these you may use:, (*26)

// change the file name
Configure::write('SchedulerShell.storeFile', "scheduler_results.json");
// change the path (note the ending /)
Configure::write('SchedulerShell.storePath', "/path/to/save/");

Preventing Simultaneous SchedulerShells Running Same Tasks

By default, the SchedulerShell will exit if it is already running and has been for less than 10 minutes. You can adjust this by setting:, (*27)

// change the number of seconds to wait before running a parallel SchedulerShell; 0 = do not exit
Configure::write('SchedulerShell.processTimeout', 5*60);

Other Notes/Known Issues

  • The optional pass arguments have not been thoroughly tested
  • PHP prior to version 5.3.6 only used relative datetime for the DateTime::modify() function. This could result in an interval of "next day 5:00" not running if the previous lastRun time was 05:02. Therefore this plugin should only be run on PHP >= 5.3.6.

The Versions

29/07 2018

dev-cakephp-v1.3

dev-cakephp-v1.3

  Sources   Download

17/06 2016

dev-master

9999999-dev http://github.com/crabstudio/cakephp-scheduler

Makes scheduling tasks in CakePHP much simpler.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp task scheduler cron job crabstudio anhtuank7c

22/05 2016

3.0.6

3.0.6.0 http://github.com/crabstudio/cakephp-scheduler

Makes scheduling tasks in CakePHP much simpler.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp task scheduler cron job crabstudio anhtuank7c

22/05 2016

3.0.5

3.0.5.0 http://github.com/crabstudio/cakephp-scheduler

Makes scheduling tasks in CakePHP much simpler.

  Sources   Download

MIT

The Requires

 

The Development Requires

cakephp task scheduler cron job crabstudio anhtuank7c

25/01 2016

dev-cakephp-v3.0

dev-cakephp-v3.0 http://github.com/trentrichardson/cakephp-scheduler

Makes scheduling tasks in CakePHP much simpler.

  Sources   Download

MIT

The Requires

  • php >=5.4.16

 

The Development Requires

cakephp task scheduler cron job

09/01 2016

3.0.4

3.0.4.0 http://github.com/trentrichardson/cakephp-scheduler

Makes scheduling tasks in CakePHP much simpler.

  Sources   Download

MIT

The Requires

  • php >=5.3.6

 

cakephp task scheduler cron job

21/12 2015

3.0.3

3.0.3.0 http://github.com/trentrichardson/cakephp-scheduler

Makes scheduling tasks in CakePHP much simpler.

  Sources   Download

MIT

The Requires

  • php >=5.3.6

 

cakephp task scheduler cron job

30/11 2015

3.0.2

3.0.2.0 http://github.com/trentrichardson/cakephp-scheduler

Makes scheduling tasks in CakePHP much simpler.

  Sources   Download

MIT

The Requires

  • php >=5.3.6

 

cakephp task scheduler cron job

16/07 2015

3.0.1

3.0.1.0 http://github.com/trentrichardson/cakephp-scheduler

Makes scheduling tasks in CakePHP much simpler.

  Sources   Download

MIT

The Requires

 

cakephp task scheduler cron job

16/07 2015

dev-cakephp-v2.0

dev-cakephp-v2.0 http://github.com/trentrichardson/cakephp-scheduler

Makes scheduling tasks in CakePHP much simpler.

  Sources   Download

MIT

The Requires

 

cakephp task scheduler cron job

16/07 2015

2.0.1

2.0.1.0 http://github.com/trentrichardson/cakephp-scheduler

Makes scheduling tasks in CakePHP much simpler.

  Sources   Download

MIT

The Requires

 

cakephp task scheduler cron job

23/04 2015

3.0.0

3.0.0.0 http://github.com/trentrichardson/cakephp-scheduler

Makes scheduling tasks in CakePHP much simpler.

  Sources   Download

MIT

The Requires

 

cakephp task scheduler cron job

19/03 2015

2.0.0

2.0.0.0 http://github.com/trentrichardson/cakephp-scheduler

Makes scheduling tasks in CakePHP much simpler.

  Sources   Download

MIT

The Requires

 

cakephp task scheduler cron job

19/03 2015

1.0.0

1.0.0.0 http://github.com/trentrichardson/cakephp-scheduler

Makes scheduling tasks in CakePHP much simpler.

  Sources   Download

MIT

The Requires

 

cakephp task scheduler cron job