-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add preconfigutred Cron Services #719
Changes from all commits
d9a50ee
86eaf7c
da7d961
1c30d26
5ed136f
32c1f61
f168b33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class seems to create a |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry\SentryBundle\Monitor; | ||
|
||
use Sentry\CheckIn; | ||
use Sentry\CheckInStatus; | ||
use Sentry\Event; | ||
use Sentry\MonitorConfig; | ||
use Sentry\State\HubInterface; | ||
|
||
class Monitor implements MonitorInterface | ||
{ | ||
/** | ||
* @var HubInterface | ||
*/ | ||
private $hub; | ||
|
||
/** | ||
* @var MonitorConfig | ||
*/ | ||
private $monitorConfig; | ||
/** | ||
* @var string | ||
*/ | ||
private $environment; | ||
/** | ||
* @var string | ||
*/ | ||
private $slug; | ||
/** | ||
* @var string|null | ||
*/ | ||
private $release; | ||
|
||
public function __construct( | ||
HubInterface $hub, | ||
MonitorConfig $monitorConfig, | ||
string $slug, | ||
string $environment, | ||
string $release = null | ||
) { | ||
$this->monitorConfig = $monitorConfig; | ||
$this->environment = $environment; | ||
$this->slug = $slug; | ||
$this->hub = $hub; | ||
$this->release = $release; | ||
} | ||
|
||
public function inProgress(CheckIn $previous = null): CheckIn | ||
{ | ||
$event = Event::createCheckIn(); | ||
$checkIn = new CheckIn( | ||
$this->slug, | ||
CheckInStatus::inProgress(), | ||
$previous ? $previous->getId() : null, | ||
$this->release, | ||
$this->environment, | ||
null, | ||
$this->monitorConfig | ||
); | ||
$event->setCheckIn($checkIn); | ||
$this->hub->captureEvent($event); | ||
|
||
return $checkIn; | ||
} | ||
|
||
public function error(CheckIn $previous = null): CheckIn | ||
{ | ||
$event = Event::createCheckIn(); | ||
$checkIn = new CheckIn( | ||
$this->slug, | ||
CheckInStatus::error(), | ||
$previous ? $previous->getId() : null, | ||
$this->release, | ||
$this->environment, | ||
null, | ||
$this->monitorConfig | ||
); | ||
$event->setCheckIn($checkIn); | ||
$this->hub->captureEvent($event); | ||
|
||
return $checkIn; | ||
} | ||
|
||
public function ok(CheckIn $previous = null): CheckIn | ||
{ | ||
$event = Event::createCheckIn(); | ||
$checkIn = new CheckIn( | ||
$this->slug, | ||
CheckInStatus::ok(), | ||
$previous ? $previous->getId() : null, | ||
$this->release, | ||
$this->environment, | ||
null, | ||
$this->monitorConfig | ||
); | ||
$event->setCheckIn($checkIn); | ||
$this->hub->captureEvent($event); | ||
|
||
return $checkIn; | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, this is about a |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry\SentryBundle\Monitor; | ||
|
||
use Sentry\MonitorConfig; | ||
use Sentry\SentrySdk; | ||
|
||
class MonitorFactory implements MonitorFactoryInterface | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $environment; | ||
/** | ||
* @var string|null | ||
*/ | ||
private $release; | ||
|
||
/** | ||
* @param string $environment the configured environment | ||
*/ | ||
public function __construct(string $environment, string $release = null) | ||
{ | ||
$this->environment = $environment; | ||
$this->release = $release; | ||
} | ||
|
||
public function getMonitor(string $slug, MonitorConfig $monitorConfig): MonitorInterface | ||
{ | ||
$hub = SentrySdk::getCurrentHub(); | ||
|
||
return new Monitor($hub, $monitorConfig, $slug, $this->environment, $this->release); | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same naming issuse |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry\SentryBundle\Monitor; | ||
|
||
use Sentry\MonitorConfig; | ||
|
||
interface MonitorFactoryInterface | ||
{ | ||
/** | ||
* @param MonitorConfig $monitorConfig the monitor configuration | ||
* | ||
* @return MonitorInterface the monitor | ||
*/ | ||
public function getMonitor(string $slug, MonitorConfig $monitorConfig): MonitorInterface; | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same naming issuse |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry\SentryBundle\Monitor; | ||
|
||
use Sentry\CheckIn; | ||
|
||
interface MonitorInterface | ||
{ | ||
public function inProgress(CheckIn $previous = null): CheckIn; | ||
|
||
public function error(CheckIn $previous = null): CheckIn; | ||
|
||
public function ok(CheckIn $previous = null): CheckIn; | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You likely want to rename the class and file. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry\SentryBundle\Tests\Cron; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Sentry\MonitorConfig; | ||
use Sentry\MonitorSchedule; | ||
use Sentry\MonitorScheduleUnit; | ||
use Sentry\SentryBundle\Monitor\MonitorFactory; | ||
use Sentry\SentryBundle\Monitor\MonitorInterface; | ||
|
||
class CronJobFactoryTest extends TestCase | ||
{ | ||
public function testCronJob(): void | ||
{ | ||
// Setup test | ||
$factory = new MonitorFactory('test', 'test-release'); | ||
$monitorConfig = new MonitorConfig( | ||
MonitorSchedule::crontab('*/5 * * * *'), | ||
5, | ||
30, | ||
'UTC' | ||
); | ||
$cronJob = $factory->getMonitor('test-cronjob', $monitorConfig); | ||
$this->assertInstanceOf(MonitorInterface::class, $cronJob); | ||
|
||
// Create a CheckIn | ||
$checkIn = $cronJob->inProgress(); | ||
$this->assertEquals('test', $checkIn->getEnvironment()); | ||
$this->assertEquals('test-release', $checkIn->getRelease()); | ||
$this->assertEquals('test-cronjob', $checkIn->getMonitorSlug()); | ||
} | ||
|
||
public function testInterval(): void | ||
{ | ||
// Setup test | ||
$factory = new MonitorFactory('test', 'test-release'); | ||
$monitorConfig = new MonitorConfig( | ||
MonitorSchedule::interval( | ||
30, | ||
MonitorScheduleUnit::minute() | ||
), | ||
5, | ||
30, | ||
'UTC' | ||
); | ||
$interval = $factory->getMonitor('test-interval', $monitorConfig); | ||
$this->assertInstanceOf(MonitorInterface::class, $interval); | ||
|
||
// Create a CheckIn | ||
$checkIn = $interval->inProgress(); | ||
$this->assertEquals('test', $checkIn->getEnvironment()); | ||
$this->assertEquals('test-release', $checkIn->getRelease()); | ||
$this->assertEquals('test-interval', $checkIn->getMonitorSlug()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An event should always have an environment set and defaults to
production
. See https://github.com/getsentry/sentry-php/blob/master/src/Event.php#L19