Skip to content

Commit

Permalink
Update crontab event dependencies and monitor configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
huangdijia committed Jan 24, 2024
1 parent 93cb4af commit 474bba2
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions src/sentry/src/Crons/Listener/CronEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,37 @@ public function process(object $event): void
return;
}

$checkinMargin = (int) ($options['checkin_margin'] ?? $this->config->get('sentry.crons.checkin_margin', 5));
$maxRuntime = (int) ($options['max_runtime'] ?? $this->config->get('sentry.crons.max_runtime', 15));
$timezone = null;

if (method_exists($event->crontab, 'getTimezone')) {
$timezone = $event->crontab->getTimezone();
$updateMonitorConfig = (bool) ($options['update_monitor_config'] ?? true);
$monitorConfig = null;

if ($updateMonitorConfig) {
$monitorSchedule = \Sentry\MonitorSchedule::crontab($rule);
$checkinMargin = (int) ($options['checkin_margin'] ?? $this->config->get('sentry.crons.checkin_margin', 5));
$maxRuntime = (int) ($options['max_runtime'] ?? $this->config->get('sentry.crons.max_runtime', 15));
$timezone = null;
if (method_exists($event->crontab, 'getTimezone')) {
$timezone = $event->crontab->getTimezone();
}
$timezone ??= $this->config->get('sentry.crons.timezone', date_default_timezone_get());
$failureIssueThreshold = isset($options['failure_issue_threshold']) ? (int) $options['failure_issue_threshold'] : null;
$recoveryThreshold = isset($options['recovery_threshold']) ? (int) $options['recovery_threshold'] : null;

$monitorConfig = new \Sentry\MonitorConfig(
schedule: $monitorSchedule,
checkinMargin: $checkinMargin,
maxRuntime: $maxRuntime,
timezone: $timezone,
failureIssueThreshold: $failureIssueThreshold,
recoveryThreshold: $recoveryThreshold,
);
}

$timezone ??= $this->config->get('sentry.crons.timezone', date_default_timezone_get());

$monitorSchedule = \Sentry\MonitorSchedule::crontab($rule);
$monitorConfig = new \Sentry\MonitorConfig(
schedule: $monitorSchedule,
checkinMargin: $checkinMargin,
maxRuntime: $maxRuntime,
timezone: $timezone,
);
$checkInId = $hub->captureCheckIn(
slug: $slug,
status: CheckInStatus::inProgress(),
monitorConfig: $monitorConfig,
);

Context::set(Constants::CRON_CHECKIN_ID, $checkInId);
}

Expand Down

0 comments on commit 474bba2

Please sign in to comment.