Added beacon events

This commit is contained in:
James Brooks 2016-08-04 11:06:27 +01:00
parent 1559e5945d
commit 9da17e7c15
8 changed files with 182 additions and 0 deletions

View File

@ -0,0 +1,24 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Bus\Events\Beacon;
use CachetHQ\Cachet\Bus\Events\EventInterface;
/**
* This is the beacon event interface.
*
* @author James Brooks <james@alt-three.com>
*/
interface BeaconEventInterface extends EventInterface
{
//
}

View File

@ -0,0 +1,22 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Bus\Events\Beacon;
/**
* This is the beacon failed to send event.
*
* @author James Brooks <james@alt-three.com>
*/
final class BeaconFailedToSendEvent implements BeaconEventInterface
{
//
}

View File

@ -0,0 +1,22 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Bus\Events\Beacon;
/**
* This is the beacon was sent event.
*
* @author James Brooks <james@alt-three.com>
*/
final class BeaconWasSentEvent implements BeaconEventInterface
{
//
}

View File

@ -21,6 +21,12 @@ class EventServiceProvider extends ServiceProvider
* @var array
*/
protected $listen = [
'CachetHQ\Cachet\Bus\Events\Beacon\BeaconFailedToSendEvent' => [
//
],
'CachetHQ\Cachet\Bus\Events\Beacon\BeaconWasSentEvent' => [
//
],
'CachetHQ\Cachet\Bus\Events\ComponentGroup\ComponentGroupWasAddedEvent' => [
//
],

View File

@ -17,6 +17,8 @@ use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Cachet\Models\User;
use CachetHQ\Cachet\Settings\Repository as Setting;
use CachetHQ\Cachet\Bus\Events\Beacon\BeaconWasSentEvent;
use CachetHQ\Cachet\Bus\Events\Beacon\BeaconFailedToSendEvent;
use Exception;
use GuzzleHttp\Client;
use Illuminate\Contracts\Config\Repository;
@ -110,6 +112,11 @@ class Beacon implements BeaconContract
]);
} catch (Exception $e) {
// TODO: Log a warning that the beacon could not be sent.
event(new BeaconFailedToSendEvent());
return;
}
event(new BeaconWasSentEvent());
}
}

View File

@ -0,0 +1,31 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Tests\Cachet\Bus\Events\Beacon;
use AltThree\TestBench\EventTrait;
use CachetHQ\Cachet\Bus\Events\Beacon\BeaconEventInterface;
use CachetHQ\Tests\Cachet\AbstractTestCase;
/**
* This is the abstract beacon event test case.
*
* @author James Brooks <james@alt-three.com>
*/
abstract class AbstractBeaconEventTestCase extends AbstractTestCase
{
use EventTrait;
protected function getEventInterfaces()
{
return [BeaconEventInterface::class];
}
}

View File

@ -0,0 +1,35 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Tests\Cachet\Bus\Events\Beacon;
use CachetHQ\Cachet\Bus\Events\Beacon\BeaconFailedToSendEvent;
/**
* This is the beacon was sent event test.
*
* @author James Brooks <james@alt-three.com>
*/
class BeaconFailedToSendEventTest extends AbstractBeaconEventTestCase
{
protected function objectHasHandlers()
{
return false;
}
protected function getObjectAndParams()
{
$params = [];
$object = new BeaconFailedToSendEvent();
return compact('params', 'object');
}
}

View File

@ -0,0 +1,35 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Tests\Cachet\Bus\Events\Beacon;
use CachetHQ\Cachet\Bus\Events\Beacon\BeaconWasSentEvent;
/**
* This is the beacon was sent event test.
*
* @author James Brooks <james@alt-three.com>
*/
class BeaconWasSentEventTest extends AbstractBeaconEventTestCase
{
protected function objectHasHandlers()
{
return false;
}
protected function getObjectAndParams()
{
$params = [];
$object = new BeaconWasSentEvent();
return compact('params', 'object');
}
}