You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When queueing/monitoring a job with the ShouldBeUnique trait, the dispatch should not result in duplicate status rows in the DB.
I made a quick and dirty modification to Trackable.php based on a comment in the Lumen repo which sorts it out, but there's probably a cleaner way through:
protected function prepareStatus(array $data = [])
{
// > New condition
if ($this instanceof ShouldBeUnique) {
$uniqueId = method_exists($this, 'uniqueId')
? $this->uniqueId()
: ($this->uniqueId ?? '');
$cache = method_exists($this, 'uniqueVia')
? $this->uniqueVia()
: Container::getInstance()->make(Cache::class);
$uniqueFor = $this->uniqueFor ?? 0;
$lock = $cache->lock( 'laravel_unique_job:' . get_class($this) . $uniqueId, $uniqueFor);
// this job is already queued and should be unique. Do not track.
if (true !== $lock->get()) {
$this->shouldTrack = false;
} else {
// release the lock if we locked it, otherwise it won't queue
$lock->release();
}
}
// <
if (!$this->shouldTrack) {
return;
}
/** @var JobStatus */
$entityClass = app(config('job-status.model'));
$data = array_merge(['type' => $this->getDisplayName()], $data);
/** @var JobStatus */
$status = $entityClass::query()->create($data);
$this->statusId = $status->getKey();
return;
}
The text was updated successfully, but these errors were encountered:
When queueing/monitoring a job with the ShouldBeUnique trait, the dispatch should not result in duplicate status rows in the DB.
I made a quick and dirty modification to Trackable.php based on a comment in the Lumen repo which sorts it out, but there's probably a cleaner way through:
The text was updated successfully, but these errors were encountered: