Skip to content
Closed
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
25 changes: 22 additions & 3 deletions src/Illuminate/Foundation/Queue/InteractsWithUniqueJobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace Illuminate\Foundation\Queue;

use Illuminate\Bus\UniqueLock;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Support\Facades\Context;
use UnexpectedValueException;

trait InteractsWithUniqueJobs
{
Expand Down Expand Up @@ -45,11 +47,28 @@ public function removeUniqueJobInformationFromContext($job): void
*
* @param mixed $job
* @return string|null
*
* @throws UnexpectedValueException
*/
protected function getUniqueJobCacheStore($job): ?string
{
return method_exists($job, 'uniqueVia')
? $job->uniqueVia()->getName()
: config('cache.default');
if (! method_exists($job, 'uniqueVia')) {
return config('cache.default');
}

/** @var Repository $repository */
$repository = $job->uniqueVia();

if (! $repository instanceof Repository) {
$message = sprintf(
'Method uniqueVia() of %s must return an implementation of %s interface',
$job::class,
Repository::class
);

throw new UnexpectedValueException($message);
}

return $job->uniqueVia()->getName();
}
}