2017 © Pedro Peláez
 

yii2-extension yii2-cron

Cron implementation for yii2 framework. Executes scheduled commands defined in yii config.

image

bpetheo/yii2-cron

Cron implementation for yii2 framework. Executes scheduled commands defined in yii config.

  • Wednesday, July 26, 2017
  • by bpetheo
  • Repository
  • 1 Watchers
  • 3 Stars
  • 600 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 9 Versions
  • 3 % Grown

The README.md

yii2-cron

Cron implementation for yii2 framework. Executes scheduled commands defined in yii config. So if you need to add/remove or reschedule a cron job you only need to modify and deploy the config file, no fiddling with crontab or other actions required. Handy if you are deploying many apps and/or deploy to multiple servers. Only requires server side scripts installed once and it is ready to use. The server side scripts can handle multiple projects (including automatic discovery of added/removed repos). They can be found here: https://github.com/bpetheo/autocron-server, (*1)

You can also assign tags to jobs, so if you use the same config file on multiple servers you can still have different cron jobs running (or the same jobs with different timings), (*2)

The component does some basic logging to runtime/logs/{command}.{action}.{date}.log, (*3)

Installation

Get via composer: composer require bpetheo/yii2-cron ~1.0.0, (*4)

Add to the controller map in config/console.php:, (*5)

'controllerMap' => [
    // ...
    'cron' => [
        'class' => 'bpetheo\yii2cron\CronController',
        'defaultAction' => 'run',
    ],
],

Configuration

When setting up timing values you can use the standard cron syntax elements (*, */5, 15, 0,30). The command should be the command/action arguments of ./yii. For example if you would set /path_to_project/yii hello/index in the standard cron tab the command in config you want to use will be hello/index., (*6)

Full configuration block looks like this:, (*7)

'params' => [
        // other parameters...
        'cronTab' => [
            // run hello/index command every 5 minutes on 21th septermber and
            // 21th december in default and dev environment
            'Sample cronjob - full config' => [
                'enabled' => true,
                'command'=>'hello/index',
                'timing' => [
                    'min' => '*/5',
                    'hour' => '*',
                    'day' => '21',
                    'month' => '9,12',
                    'dayofweek' => '*',
                ],
                'tags' => [
                    'default',
                    'development',
                ],
            ],
        // other parameters...
    ],

You can also use a simplified format by setting only the parameters differing from defaults:, (*8)

'params' => [
        // other parameters...
        'cronTab' => [
            // execute hello/index every 30 minuted
            // short form, only non-default values are set explicitly
            'Sample cronjob - short config' => [
                'enabled' => true,
                'command'=>'hello',
                'timing' => [
                    'min' => '0,30',
                ],
            ],
        ],
        // other parameters...
    ],

Only command parameter required. Also simple string format like * * * * * controller/action avalible., (*9)

'params' => [
        // other parameters...
        'cronTab' => [
            // both cron jobs controller/action1 and controller/action2
            // valid and runs every minute
            [
                'command'=>'controller/action1',
            ],
            '* * * * * controller/action2',
        ],
        // other parameters...
    ],

Contributing

I've made this project to fit my own needs. You might have different use cases which is not covered, but feel free to extend or modify the code to make it suitable to more people., (*10)

The Versions

26/07 2017

dev-master

9999999-dev

Cron implementation for yii2 framework. Executes scheduled commands defined in yii config.

  Sources   Download

GPL-3.0

The Requires

 

by Bence Petheő

extension yii2 cron yii2 cron yii2cron

26/07 2017

1.0.7

1.0.7.0

Cron implementation for yii2 framework. Executes scheduled commands defined in yii config.

  Sources   Download

GPL-3.0

The Requires

 

by Bence Petheő

extension yii2 cron yii2 cron yii2cron

25/07 2017

1.0.6

1.0.6.0

Cron implementation for yii2 framework. Executes scheduled commands defined in yii config.

  Sources   Download

GPL-3.0

The Requires

 

by Bence Petheő

extension yii2 cron yii2 cron yii2cron

25/07 2017

1.0.5

1.0.5.0

Cron implementation for yii2 framework. Executes scheduled commands defined in yii config.

  Sources   Download

GPL-3.0

The Requires

 

by Bence Petheő

extension yii2 cron yii2 cron yii2cron

18/01 2017

1.0.4

1.0.4.0

Cron implementation for yii2 framework. Executes scheduled commands defined in yii config.

  Sources   Download

GPL-3.0

The Requires

 

by Bence Petheő

extension yii2 cron yii2 cron yii2cron

18/01 2017

1.0.3

1.0.3.0

Cron implementation for yii2 framework. Executes scheduled commands defined in yii config.

  Sources   Download

GPL-3.0

The Requires

 

by Bence Petheő

extension yii2 cron yii2 cron yii2cron

17/01 2017

1.0.2

1.0.2.0

Cron implementation for yii2 framework. Executes scheduled commands defined in yii config.

  Sources   Download

GPL-3.0

The Requires

 

by Bence Petheő

extension yii2 cron yii2 cron yii2cron

10/01 2017

1.0.1

1.0.1.0

Cron implementation for yii2 framework. Executes scheduled commands defined in yii config.

  Sources   Download

GPL-3.0

The Requires

 

by Bence Petheő

extension yii2 cron yii2 cron yii2cron

09/01 2017

1.0.0

1.0.0.0

Cron implementation for yii2 framework. Executes scheduled commands defined in yii config.

  Sources   Download

GPL-3.0

The Requires

 

by Bence Petheő

extension yii2 cron yii2 cron yii2cron