alexeevdv/yii2-queue-checker

1.1.0 2018-11-19 12:07 UTC

This package is auto-updated.

Last update: 2024-11-20 01:26:16 UTC


README

Build Status codecov PHP 5.4 PHP 5.5 PHP 5.6 PHP 7.0 PHP 7.1 PHP 7.2

Usage example

<?php
return [
// ...
    'components' => [
        'smsProvider' => [
            'class' => \mikk150\sms\ProviderInterface::class,       
        ],
        'mailer' => [
            'class' => \yii\mail\MailerInterface::class,
        ],
    ],
    'controllerMap' => [
        'queue-checker' => [
            'class' => \alexeevdv\yii\queue\checker\CheckController::class,
            'checkActionConfig' => [
                'class' => \alexeevdv\yii\queue\checker\CheckAction::class,
                'alarms' => [
                    [
                        'class' => \alexeevdv\yii\queue\checker\SmsAlarm::class,
                        'provider' => 'smsProvider',
                        'from' => 'Queue',
                        'to' => [
                            '+123456789',
                            '+987654321',
                        ],
                    ],
                    [
                        'class' => \alexeevdv\yii\queue\checker\MailerAlarm::class,
                        'subject' => 'Queue status notication',
                        'from' => 'Queue',
                        'to' => [
                            'admin@example.org',
                            'suppoer@example.org',
                        ],
                    ],
                ],
            ],
        ],
    ],
// ...
];
./yii queue-checker

Custom alarm example

<?php
namespace common\components;

use alexeevdv\yii\queue\checker\AlarmInterface;
use yii\base\BaseObject;
use yii\di\Instance;
use yii\httpclient\Client;

class WebhookAlarm extends BaseObject implements AlarmInterface 
{
    public $httpClient = Client::class;
    
    public $webHook;

    public function send($downtime)
    {
        Instance::ensure($this->httpClient, Client::class)->post($this->webhook, [
            'downtime' => $downtime,
        ]);
    }
}
<?php
return [
// ...
   'controllerMap' => [
       'queue-checker' => [
           'class' => \alexeevdv\yii\queue\checker\CheckController::class,
           'checkActionConfig' => [
               'class' => \alexeevdv\yii\queue\checker\CheckAction::class,
               'alarms' => [
                   [
                        'class' => \common\components\WebhookAlarm::class,
                        'webhook' => 'http://your-webhook-here',
                   ],
               ],
           ],
       ],
   ],
// ...
];