2017 © Pedro Peláez
 

yii2-extension yii2-cron-log

Component for logging cron jobs

image

yii2mod/yii2-cron-log

Component for logging cron jobs

  • Tuesday, September 12, 2017
  • by disem
  • Repository
  • 4 Watchers
  • 18 Stars
  • 6,493 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 9 Forks
  • 0 Open issues
  • 10 Versions
  • 4 % Grown

The README.md

, (*1)

Yii2 Cron Log Extension


Component for logging cron jobs., (*2)

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

Installation

The preferred way to install this extension is through composer., (*4)

Either run, (*5)

php composer.phar require --prefer-dist yii2mod/yii2-cron-log "*"

or add, (*6)

"yii2mod/yii2-cron-log": "*"

to the require section of your composer.json., (*7)

Configuration

Database Migrations, (*8)

Before using this extension, we'll also need to prepare the database., (*9)

php yii migrate/up --migrationPath=@yii2mod/cron/migrations

Error Handler and File Mutex Setup, (*10)

Error handler must be defined inside console config, it will be used to log exceptions into database., (*11)

FileMutex implements mutex "lock" mechanism via local file system files., (*12)

Add the following code to your console application configuration:, (*13)

'components' => [
    'errorHandler' => [
        'class' => 'yii2mod\cron\components\ErrorHandler',
    ],
    'mutex' => [
        'class' => 'yii\mutex\FileMutex'
    ],
],

Usage

1) To access the list of executed commands, you need to define CronLogAction in any controller (for example /modules/admin/SettingsController.php):, (*14)

    public function actions()
    {
        return [
            'cron' => 'yii2mod\cron\actions\CronLogAction',
            // Also you can override some action properties in following way:
            'cron' => [
                'class' => 'yii2mod\cron\actions\CronLogAction',
                'searchClass' => [
                    'class' => 'yii2mod\cron\models\search\CronScheduleSearch',
                    'pageSize' => 10
                ],
                'view' => 'custom name of the view, which should be rendered.'
            ]
        ];
    }

This action is used to view list of executed commands: http://project.com/admin/settings/cron, (*15)

2) To log cron actions you should add behavior to all commands that should be logged. In the following example CronLoggerBehavior will be log the index action., (*16)


namespace app\commands; use yii\console\Controller; /** * This command echoes the first argument that you have entered. * * This command is provided as an example for you to learn how to create console commands. * */ class HelloController extends Controller { public function behaviors() { return [ 'cronLogger' => [ 'class' => 'yii2mod\cron\behaviors\CronLoggerBehavior', 'actions' => ['index'] ], // Example of usage the `MutexConsoleCommandBehavior` 'mutexBehavior' => [ 'class' => 'yii2mod\cron\behaviors\MutexConsoleCommandBehavior', 'mutexActions' => ['index'], 'timeout' => 3600, //default 0 ] ]; } /** * This command echoes what you have entered as the message. * @param string $message the message to be echoed. */ public function actionIndex($message = 'hello world') { echo $message . "\n"; } }

Internationalization

All text and messages introduced in this extension are translatable under category 'yii2mod-cron-log'. You may use translations provided within this extension, using following application configuration:, (*17)

return [
    'components' => [
        'i18n' => [
            'translations' => [
                'yii2mod-cron-log' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@yii2mod/cron/messages',
                ],
                // ...
            ],
        ],
        // ...
    ],
    // ...
];

Support us

Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff., (*18)

The Versions

12/09 2017

dev-master

9999999-dev

Component for logging cron jobs

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy
by Igor Chepurnoi

yii2 cron log cron log logging cron jobs

12/12 2016

1.5

1.5.0.0

Component for logging cron jobs

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 cron log cron log logging cron jobs

22/11 2016

1.4

1.4.0.0

Component for logging cron jobs

  Sources   Download

MIT

The Requires

 

The Development Requires

by Igor Chepurnoy

yii2 cron log cron log logging cron jobs

13/11 2016

1.3

1.3.0.0

Component for logging cron jobs

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

yii2 cron log cron log logging cron jobs

09/11 2016

1.2.1

1.2.1.0

Component for logging cron jobs

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

yii2 cron log cron log logging cron jobs

09/11 2016

1.2

1.2.0.0

Component for logging cron jobs

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

yii2 cron log cron log logging cron jobs

04/08 2016

1.1

1.1.0.0

Component for logging cron jobs

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

yii2 cron log cron log logging cron jobs

21/06 2016

1.0.2

1.0.2.0

Component for logging cron jobs

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

19/11 2015

1.0.1

1.0.1.0

Component for logging cron jobs

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2

20/07 2015

1.0

1.0.0.0

Component for logging cron jobs

  Sources   Download

MIT

The Requires

 

by Igor Chepurnoy

extension yii2