Skip to content

Commit

Permalink
Update ProcessStamp.php (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander White authored and Tom Schlick committed May 19, 2020
1 parent 0ed2564 commit 8c9af8d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/ProcessStamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;

class ProcessStamp extends Model
{
Expand Down Expand Up @@ -57,11 +58,13 @@ public static function firstOrCreateByProcess(array $process, ?string $hash = nu
$parent = static::firstOrCreateByProcess(static::getProcessName($process['type'], $process['parent_name']));
}

return static::firstOrCreate(['hash' => $hash], [
'name' => trim($process['name']),
'type' => $process['type'],
'parent_id' => optional($parent)->getKey(),
]);
return DB::transaction(function () use ($hash, $process, $parent) {
return static::lockForUpdate()->firstOrCreate(['hash' => $hash], [
'name' => trim($process['name']),
'type' => $process['type'],
'parent_id' => optional($parent)->getKey(),
]);
}, 5);
}

/**
Expand Down

0 comments on commit 8c9af8d

Please sign in to comment.