diff --git a/src/Sentry/Laravel/Features/ConsoleSchedulingIntegration.php b/src/Sentry/Laravel/Features/ConsoleSchedulingIntegration.php index 6deda1fe..3de5e4d4 100644 --- a/src/Sentry/Laravel/Features/ConsoleSchedulingIntegration.php +++ b/src/Sentry/Laravel/Features/ConsoleSchedulingIntegration.php @@ -6,6 +6,7 @@ use Illuminate\Console\Application as ConsoleApplication; use Illuminate\Console\Scheduling\Event as SchedulingEvent; use Illuminate\Contracts\Cache\Factory as Cache; +use Illuminate\Contracts\Cache\Repository; use Illuminate\Support\Str; use RuntimeException; use Sentry\CheckIn; @@ -17,6 +18,11 @@ class ConsoleSchedulingIntegration extends Feature { + /** + * @var string|null + */ + private $cacheStore = null; + /** * @var array The list of checkins that are currently in progress. */ @@ -109,6 +115,11 @@ public function onBootInactive(): void $this->shouldHandleCheckIn = false; } + public function useCacheStore(?string $name): void + { + $this->cacheStore = $name; + } + private function startCheckIn( ?string $slug, SchedulingEvent $scheduled, @@ -148,7 +159,7 @@ private function startCheckIn( $this->checkInStore[$cacheKey] = $checkIn; if ($scheduled->runInBackground) { - $this->resolveCache()->store()->put($cacheKey, $checkIn->getId(), $scheduled->expiresAt * 60); + $this->resolveCache()->put($cacheKey, $checkIn->getId(), $scheduled->expiresAt * 60); } $this->sendCheckIn($checkIn); @@ -169,7 +180,7 @@ private function finishCheckIn(?string $slug, SchedulingEvent $scheduled, CheckI $checkIn = $this->checkInStore[$cacheKey] ?? null; if ($checkIn === null && $scheduled->runInBackground) { - $checkInId = $this->resolveCache()->store()->get($cacheKey); + $checkInId = $this->resolveCache()->get($cacheKey); if ($checkInId !== null) { $checkIn = $this->createCheckIn($checkInSlug, $status, $checkInId); @@ -185,7 +196,7 @@ private function finishCheckIn(?string $slug, SchedulingEvent $scheduled, CheckI unset($this->checkInStore[$mutex]); if ($scheduled->runInBackground) { - $this->resolveCache()->store()->forget($cacheKey); + $this->resolveCache()->forget($cacheKey); } $checkIn->setStatus($status); @@ -237,8 +248,8 @@ private function makeSlugForScheduled(SchedulingEvent $scheduled): string return "scheduled_{$generatedSlug}"; } - private function resolveCache(): Cache + private function resolveCache(): Repository { - return $this->container()->make(Cache::class); + return $this->container()->make(Cache::class)->store($this->cacheStore); } }