-
-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for Cron Monitoring (#1467)
- Loading branch information
Showing
8 changed files
with
344 additions
and
3 deletions.
There are no files selected for viewing
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,117 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry; | ||
|
||
use Sentry\Util\SentryUid; | ||
|
||
final class CheckIn | ||
{ | ||
/** | ||
* @var string The check-in ID | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string The monitor slug | ||
*/ | ||
private $monitorSlug; | ||
|
||
/** | ||
* @var \Sentry\CheckInStatus The status of the check-in | ||
*/ | ||
private $status; | ||
|
||
/** | ||
* @var string|null The release | ||
*/ | ||
private $release; | ||
|
||
/** | ||
* @var string|null The environment | ||
*/ | ||
private $environment; | ||
|
||
/** | ||
* @var int|null The duration of the check in seconds | ||
*/ | ||
private $duration; | ||
|
||
public function __construct( | ||
string $monitorSlug, | ||
CheckInStatus $status, | ||
string $id = null, | ||
?string $release = null, | ||
?string $environment = null, | ||
?int $duration = null | ||
) { | ||
$this->setMonitorSlug($monitorSlug); | ||
$this->setStatus($status); | ||
|
||
$this->setId($id ?? SentryUid::generate()); | ||
$this->setRelease($release ?? ''); | ||
$this->setEnvironment($environment ?? Event::DEFAULT_ENVIRONMENT); | ||
$this->setDuration($duration); | ||
} | ||
|
||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setId(string $id): void | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
public function getMonitorSlug(): string | ||
{ | ||
return $this->monitorSlug; | ||
} | ||
|
||
public function setMonitorSlug(string $monitorSlug): void | ||
{ | ||
$this->monitorSlug = $monitorSlug; | ||
} | ||
|
||
public function getStatus(): CheckInStatus | ||
{ | ||
return $this->status; | ||
} | ||
|
||
public function setStatus(CheckInStatus $status): void | ||
{ | ||
$this->status = $status; | ||
} | ||
|
||
public function getRelease(): ?string | ||
{ | ||
return $this->release; | ||
} | ||
|
||
public function setRelease(string $release): void | ||
{ | ||
$this->release = $release; | ||
} | ||
|
||
public function getEnvironment(): ?string | ||
{ | ||
return $this->environment; | ||
} | ||
|
||
public function setEnvironment(string $environment): void | ||
{ | ||
$this->environment = $environment; | ||
} | ||
|
||
public function getDuration(): ?int | ||
{ | ||
return $this->duration; | ||
} | ||
|
||
public function setDuration(?int $duration): void | ||
{ | ||
$this->duration = $duration; | ||
} | ||
} |
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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry; | ||
|
||
/** | ||
* This enum represents all the possible status of a check in. | ||
*/ | ||
final class CheckInStatus implements \Stringable | ||
{ | ||
/** | ||
* @var string The value of the enum instance | ||
*/ | ||
private $value; | ||
|
||
/** | ||
* @var array<string, self> A list of cached enum instances | ||
*/ | ||
private static $instances = []; | ||
|
||
private function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
public static function ok(): self | ||
{ | ||
return self::getInstance('ok'); | ||
} | ||
|
||
public static function error(): self | ||
{ | ||
return self::getInstance('error'); | ||
} | ||
|
||
public static function inProgress(): self | ||
{ | ||
return self::getInstance('in_progress'); | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->value; | ||
} | ||
|
||
private static function getInstance(string $value): self | ||
{ | ||
if (!isset(self::$instances[$value])) { | ||
self::$instances[$value] = new self($value); | ||
} | ||
|
||
return self::$instances[$value]; | ||
} | ||
} |
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
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,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Sentry\CheckIn; | ||
use Sentry\CheckInStatus; | ||
use Sentry\Util\SentryUid; | ||
|
||
final class CheckInTest extends TestCase | ||
{ | ||
public function testConstructor(): void | ||
{ | ||
$checkInId = SentryUid::generate(); | ||
$checkIn = new CheckIn( | ||
'my-monitor', | ||
CheckInStatus::ok(), | ||
$checkInId, | ||
'1.0.0', | ||
'dev', | ||
10 | ||
); | ||
|
||
$this->assertEquals($checkInId, $checkIn->getId()); | ||
$this->assertEquals('my-monitor', $checkIn->getMonitorSlug()); | ||
$this->assertEquals('ok', $checkIn->getStatus()); | ||
$this->assertEquals('1.0.0', $checkIn->getRelease()); | ||
$this->assertEquals('dev', $checkIn->getEnvironment()); | ||
$this->assertEquals(10, $checkIn->getDuration()); | ||
} | ||
|
||
/** | ||
* @dataProvider gettersAndSettersDataProvider | ||
*/ | ||
public function testGettersAndSetters(string $getterMethod, string $setterMethod, $expectedData): void | ||
{ | ||
$checkIn = new CheckIn( | ||
'my-monitor', | ||
CheckInStatus::ok() | ||
); | ||
$checkIn->$setterMethod($expectedData); | ||
|
||
$this->assertEquals($expectedData, $checkIn->$getterMethod()); | ||
} | ||
|
||
public function gettersAndSettersDataProvider(): array | ||
{ | ||
return [ | ||
['getId', 'setId', SentryUid::generate()], | ||
['getMonitorSlug', 'setMonitorSlug', 'my-monitor'], | ||
['getStatus', 'setStatus', CheckInStatus::ok()], | ||
['getRelease', 'setRelease', '1.0.0'], | ||
['getEnvironment', 'setEnvironment', 'dev'], | ||
['getDuration', 'setDuration', 10], | ||
]; | ||
} | ||
} |
Oops, something went wrong.