forked from getsentry/sentry-symfony
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust wording and add Cron Monitor upsert
- Loading branch information
Showing
8 changed files
with
121 additions
and
72 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry\SentryBundle\Tests\Cron; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Sentry\SentryBundle\Cron\CronJobFactory; | ||
use Sentry\SentryBundle\Cron\CronJobInterface; | ||
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 CronJobFactory('test', 'test-release'); | ||
$cronjob = $factory->getCronjob('test-monitor'); | ||
$this->assertInstanceOf(CronJobInterface::class, $cronjob); | ||
$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 = $cronjob->inProgress(); | ||
$checkIn = $interval->inProgress(); | ||
$this->assertEquals('test', $checkIn->getEnvironment()); | ||
$this->assertEquals('test-release', $checkIn->getRelease()); | ||
$this->assertEquals('test-monitor', $checkIn->getMonitorSlug()); | ||
$this->assertEquals('test-interval', $checkIn->getMonitorSlug()); | ||
} | ||
} |