Skip to content

Commit

Permalink
Add support for failure_issue_threshold & recovery_threshold (#838)
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric authored Jan 23, 2024
1 parent fbcd9bd commit 8919f41
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"require": {
"php": "^7.2 | ^8.0",
"illuminate/support": "^6.0 | ^7.0 | ^8.0 | ^9.0 | ^10.0",
"sentry/sentry": "^4.3",
"sentry/sentry": "^4.4",
"symfony/psr-http-message-bridge": "^1.0 | ^2.0 | ^6.0 | ^7.0",
"nyholm/psr7": "^1.0"
},
Expand Down
63 changes: 54 additions & 9 deletions src/Sentry/Laravel/Features/ConsoleIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,24 @@ public function onBoot(Cache $cache): void
{
$this->cache = $cache;

$startCheckIn = function (?string $slug, SchedulingEvent $scheduled, ?int $checkInMargin, ?int $maxRuntime, bool $updateMonitorConfig) {
$this->startCheckIn($slug, $scheduled, $checkInMargin, $maxRuntime, $updateMonitorConfig);
$startCheckIn = function (
?string $slug,
SchedulingEvent $scheduled,
?int $checkInMargin,
?int $maxRuntime,
bool $updateMonitorConfig,
?int $failureIssueThreshold,
?int $recoveryThreshold
) {
$this->startCheckIn(
$slug,
$scheduled,
$checkInMargin,
$maxRuntime,
$updateMonitorConfig,
$failureIssueThreshold,
$recoveryThreshold
);
};
$finishCheckIn = function (?string $slug, SchedulingEvent $scheduled, CheckInStatus $status) {
$this->finishCheckIn($slug, $scheduled, $status);
Expand All @@ -53,17 +69,35 @@ public function onBoot(Cache $cache): void
?string $monitorSlug = null,
?int $checkInMargin = null,
?int $maxRuntime = null,
bool $updateMonitorConfig = true
bool $updateMonitorConfig = true,
?int $failureIssueThreshold = null,
?int $recoveryThreshold = null
) use ($startCheckIn, $finishCheckIn) {
/** @var SchedulingEvent $this */
if ($monitorSlug === null && $this->command === null) {
throw new RuntimeException('The command string is null, please set a slug manually for this scheduled command using the `sentryMonitor(\'your-monitor-slug\')` macro.');
}

return $this
->before(function () use ($startCheckIn, $monitorSlug, $checkInMargin, $maxRuntime, $updateMonitorConfig) {
->before(function () use (
$startCheckIn,
$monitorSlug,
$checkInMargin,
$maxRuntime,
$updateMonitorConfig,
$failureIssueThreshold,
$recoveryThreshold
) {
/** @var SchedulingEvent $this */
$startCheckIn($monitorSlug, $this, $checkInMargin, $maxRuntime, $updateMonitorConfig);
$startCheckIn(
$monitorSlug,
$this,
$checkInMargin,
$maxRuntime,
$updateMonitorConfig,
$failureIssueThreshold,
$recoveryThreshold
);
})
->onSuccess(function () use ($finishCheckIn, $monitorSlug) {
/** @var SchedulingEvent $this */
Expand All @@ -83,14 +117,23 @@ public function onBootInactive(): void
?string $monitorSlug = null,
?int $checkInMargin = null,
?int $maxRuntime = null,
bool $updateMonitorConfig = true
bool $updateMonitorConfig = true,
?int $failureIssueThreshold = null,
?int $recoveryThreshold = null
) {
return $this;
});
}

private function startCheckIn(?string $slug, SchedulingEvent $scheduled, ?int $checkInMargin, ?int $maxRuntime, bool $updateMonitorConfig): void
{
private function startCheckIn(
?string $slug,
SchedulingEvent $scheduled,
?int $checkInMargin,
?int $maxRuntime,
bool $updateMonitorConfig,
?int $failureIssueThreshold,
?int $recoveryThreshold
): void {
$checkInSlug = $slug ?? $this->makeSlugForScheduled($scheduled);

$checkIn = $this->createCheckIn($checkInSlug, CheckInStatus::inProgress());
Expand All @@ -106,7 +149,9 @@ private function startCheckIn(?string $slug, SchedulingEvent $scheduled, ?int $c
MonitorSchedule::crontab($scheduled->getExpression()),
$checkInMargin,
$maxRuntime,
$timezone
$timezone,
$failureIssueThreshold,
$recoveryThreshold
));
}

Expand Down

0 comments on commit 8919f41

Please sign in to comment.