diff --git a/src/Illuminate/Queue/Middleware/WithoutOverlapping.php b/src/Illuminate/Queue/Middleware/WithoutOverlapping.php index 19b4c27fb6f2..17ed75e6feb6 100644 --- a/src/Illuminate/Queue/Middleware/WithoutOverlapping.php +++ b/src/Illuminate/Queue/Middleware/WithoutOverlapping.php @@ -6,6 +6,8 @@ use Illuminate\Contracts\Cache\Repository as Cache; use Illuminate\Support\InteractsWithTime; +use function Illuminate\Support\enum_value; + class WithoutOverlapping { use InteractsWithTime; @@ -48,13 +50,13 @@ class WithoutOverlapping /** * Create a new middleware instance. * - * @param string $key + * @param \UnitEnum|string $key * @param \DateTimeInterface|int|null $releaseAfter * @param \DateTimeInterface|int $expiresAfter */ public function __construct($key = '', $releaseAfter = 0, $expiresAfter = 0) { - $this->key = $key; + $this->key = enum_value($key); $this->releaseAfter = $releaseAfter; $this->expiresAfter = $this->secondsUntil($expiresAfter); } diff --git a/tests/Integration/Queue/WithoutOverlappingJobsTest.php b/tests/Integration/Queue/WithoutOverlappingJobsTest.php index a69c2df87e39..8f3f85f8a1eb 100644 --- a/tests/Integration/Queue/WithoutOverlappingJobsTest.php +++ b/tests/Integration/Queue/WithoutOverlappingJobsTest.php @@ -175,6 +175,26 @@ public function testGetLockUsesDisplayName() 'prefix:key', (new WithoutOverlapping('key'))->withPrefix('prefix:')->shared()->getLockKey($job) ); + + $this->assertSame( + 'prefix:'.hash('xxh128', 'App\\Actions\\WithoutOverlappingTestAction').':unit', + (new WithoutOverlapping(UnitCategory::unit))->withPrefix('prefix:')->getLockKey($job) + ); + + $this->assertSame( + 'prefix:unit', + (new WithoutOverlapping(UnitCategory::unit))->withPrefix('prefix:')->shared()->getLockKey($job) + ); + + $this->assertSame( + 'prefix:'.hash('xxh128', 'App\\Actions\\WithoutOverlappingTestAction').':backed', + (new WithoutOverlapping(BackedCategory::backed))->withPrefix('prefix:')->getLockKey($job) + ); + + $this->assertSame( + 'prefix:backed', + (new WithoutOverlapping(BackedCategory::backed))->withPrefix('prefix:')->shared()->getLockKey($job) + ); } } @@ -254,3 +274,13 @@ public function displayName(): string return 'App\\Actions\\WithoutOverlappingTestAction'; } } + +enum UnitCategory +{ + case unit; +} + +enum BackedCategory: string +{ + case backed = 'backed'; +}