Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Illuminate/Queue/Middleware/WithoutOverlapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
30 changes: 30 additions & 0 deletions tests/Integration/Queue/WithoutOverlappingJobsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
}

Expand Down Expand Up @@ -254,3 +274,13 @@ public function displayName(): string
return 'App\\Actions\\WithoutOverlappingTestAction';
}
}

enum UnitCategory
{
case unit;
}

enum BackedCategory: string
{
case backed = 'backed';
}
Loading