Skip to content

Commit

Permalink
Allow cache store used by console scheduling integration to be overri…
Browse files Browse the repository at this point in the history
…dden
  • Loading branch information
jnbeaver committed Aug 23, 2024
1 parent 78e8448 commit 87320bf
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Sentry/Laravel/Features/ConsoleSchedulingIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +18,8 @@

class ConsoleSchedulingIntegration extends Feature
{
private $cacheStore = null;

/**
* @var array<string, CheckIn> The list of checkins that are currently in progress.
*/
Expand Down Expand Up @@ -109,6 +112,11 @@ public function onBootInactive(): void
$this->shouldHandleCheckIn = false;
}

public function useCacheStore(?string $name): void
{
$this->cacheStore = $name;
}

private function startCheckIn(
?string $slug,
SchedulingEvent $scheduled,
Expand Down Expand Up @@ -148,7 +156,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);
Expand All @@ -169,7 +177,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);
Expand All @@ -185,7 +193,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);
Expand Down Expand Up @@ -237,8 +245,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);
}
}

0 comments on commit 87320bf

Please sign in to comment.