Final Class Yiisoft\Yii\Sentry\SentryCronMonitor
| Inheritance | Yiisoft\ |
|---|
Sends Sentry cron monitor check-ins for console commands configured in the cron-monitoring parameter.
The check-in is sent with in_progress status when a command starts and with either ok or error
status, derived from the exit code, when it terminates. The final status is sent on
{@see \0
results in an ok check-in.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\ |
|
| handleCommand() | Yiisoft\ |
|
| handleTerminate() | Yiisoft\ |
Method Details
| public mixed __construct ( \ | ||
| $hub | \ |
|
| $monitoring | array |
Map of console command name to a monitor slug or monitor configuration. |
public function __construct(
private readonly HubInterface $hub,
private readonly array $monitoring = [],
) {}
| public void handleCommand ( \ | ||
| $event | \ |
|
public function handleCommand(ConsoleCommandEvent $event): void
{
$command = $event->getCommand();
assert($command !== null);
$commandName = $command->getName();
if ($commandName === null || !array_key_exists($commandName, $this->monitoring)) {
return;
}
$config = $this->monitoring[$commandName];
if (!is_string($config) && !is_array($config)) {
throw new InvalidArgumentException(
sprintf(
'Sentry monitor configuration for the "%s" console command must be a string or an array, got %s.',
$commandName,
get_debug_type($config),
),
);
}
$this->slug = $this->validateSlug(is_string($config) ? $config : ($config['slug'] ?? null), $commandName);
$this->checkInId = $this->hub->captureCheckIn(
$this->slug,
CheckInStatus::inProgress(),
monitorConfig: is_array($config) ? $this->createMonitorConfig($config) : null,
);
$this->startedAt = hrtime(true);
$this->finished = false;
}
| public void handleTerminate ( \ | ||
| $event | \ |
|
public function handleTerminate(ConsoleTerminateEvent $event): void
{
$this->captureFinalCheckIn(
$event->getExitCode() === 0 ? CheckInStatus::ok() : CheckInStatus::error(),
);
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.