fix for locking race

This commit is contained in:
Lanta 2023-11-21 10:25:55 +01:00
parent 00bf93f5b4
commit 8ed6b2c32c

View file

@ -19,16 +19,22 @@ function new-lock {
if (Test-Path -Path $lockFile) { if (Test-Path -Path $lockFile) {
Write-Host "Job is already running. Sleeping 10 seconds" Write-Host "Job is already running. Sleeping 10 seconds"
Start-Sleep -Seconds 10 Start-Sleep -Seconds 10
}else{
$lock = $false
} }
if($i -ge $timeout){ else {
try {
New-Item -ItemType File -Path $lockFile | Out-Null
$lock = $false
}
catch {
$lock = $true
}
}
if ($i -ge $timeout) {
Write-Output "Timed out" Write-Output "Timed out"
exit exit
} }
$i++ $i++
} }
New-Item -ItemType File -Path $lockFile | Out-Null
if ($by) { if ($by) {
$by | Out-File -FilePath $lockFile -Append $by | Out-File -FilePath $lockFile -Append
} }