Skip to content

Commit

Permalink
[11.x] Fix unique jobs that have a uniqueVia method (#54294)
Browse files Browse the repository at this point in the history
* Adds test for uniqueVia job dispatch

* Make getName public
  • Loading branch information
DougSisk authored Jan 22, 2025
1 parent 1c2a6c1 commit 71203fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ protected function getSeconds($ttl)
*
* @return string|null
*/
protected function getName()
public function getName()
{
return $this->config['store'] ?? null;
}
Expand Down
17 changes: 17 additions & 0 deletions tests/Integration/Queue/UniqueJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Container\Container;
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
Expand Down Expand Up @@ -51,6 +52,14 @@ public function testUniqueJobsAreNotDispatched()
);
}

public function testUniqueJobWithViaDispatched()
{
Bus::fake();

UniqueViaJob::dispatch();
Bus::assertDispatched(UniqueViaJob::class);
}

public function testLockIsReleasedForSuccessfulJobs()
{
UniqueTestJob::$handled = false;
Expand Down Expand Up @@ -222,3 +231,11 @@ public function __construct(public User $user)
{
}
}

class UniqueViaJob extends UniqueTestJob
{
public function uniqueVia(): Cache
{
return Container::getInstance()->make(Cache::class);
}
}

0 comments on commit 71203fc

Please sign in to comment.