alexeevdv/yii2-queue-checker

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

1.1.0 2018-11-19 12:07 UTC

This package is auto-updated.

Last update: 2021-10-19 19:04:18 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',
                   ],
               ],
           ],
       ],
   ],
// ...
];