Skip to content

Commit 40fd30e

Browse files
authored
Allow cache store used by console scheduling integration to be overridden (#942)
1 parent 14e828d commit 40fd30e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/Sentry/Laravel/Features/ConsoleSchedulingIntegration.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Console\Application as ConsoleApplication;
77
use Illuminate\Console\Scheduling\Event as SchedulingEvent;
88
use Illuminate\Contracts\Cache\Factory as Cache;
9+
use Illuminate\Contracts\Cache\Repository;
910
use Illuminate\Support\Str;
1011
use RuntimeException;
1112
use Sentry\CheckIn;
@@ -17,6 +18,11 @@
1718

1819
class ConsoleSchedulingIntegration extends Feature
1920
{
21+
/**
22+
* @var string|null
23+
*/
24+
private $cacheStore = null;
25+
2026
/**
2127
* @var array<string, CheckIn> The list of checkins that are currently in progress.
2228
*/
@@ -109,6 +115,11 @@ public function onBootInactive(): void
109115
$this->shouldHandleCheckIn = false;
110116
}
111117

118+
public function useCacheStore(?string $name): void
119+
{
120+
$this->cacheStore = $name;
121+
}
122+
112123
private function startCheckIn(
113124
?string $slug,
114125
SchedulingEvent $scheduled,
@@ -148,7 +159,7 @@ private function startCheckIn(
148159
$this->checkInStore[$cacheKey] = $checkIn;
149160

150161
if ($scheduled->runInBackground) {
151-
$this->resolveCache()->store()->put($cacheKey, $checkIn->getId(), $scheduled->expiresAt * 60);
162+
$this->resolveCache()->put($cacheKey, $checkIn->getId(), $scheduled->expiresAt * 60);
152163
}
153164

154165
$this->sendCheckIn($checkIn);
@@ -169,7 +180,7 @@ private function finishCheckIn(?string $slug, SchedulingEvent $scheduled, CheckI
169180
$checkIn = $this->checkInStore[$cacheKey] ?? null;
170181

171182
if ($checkIn === null && $scheduled->runInBackground) {
172-
$checkInId = $this->resolveCache()->store()->get($cacheKey);
183+
$checkInId = $this->resolveCache()->get($cacheKey);
173184

174185
if ($checkInId !== null) {
175186
$checkIn = $this->createCheckIn($checkInSlug, $status, $checkInId);
@@ -185,7 +196,7 @@ private function finishCheckIn(?string $slug, SchedulingEvent $scheduled, CheckI
185196
unset($this->checkInStore[$mutex]);
186197

187198
if ($scheduled->runInBackground) {
188-
$this->resolveCache()->store()->forget($cacheKey);
199+
$this->resolveCache()->forget($cacheKey);
189200
}
190201

191202
$checkIn->setStatus($status);
@@ -237,8 +248,8 @@ private function makeSlugForScheduled(SchedulingEvent $scheduled): string
237248
return "scheduled_{$generatedSlug}";
238249
}
239250

240-
private function resolveCache(): Cache
251+
private function resolveCache(): Repository
241252
{
242-
return $this->container()->make(Cache::class);
253+
return $this->container()->make(Cache::class)->store($this->cacheStore);
243254
}
244255
}

0 commit comments

Comments
 (0)