lock sleep and timeout

This commit is contained in:
Lanta 2023-11-13 10:15:07 +01:00
parent 65a96699e9
commit 34242cc9cd

View file

@ -1,5 +1,9 @@
function new-lock { function new-lock {
Write-Output 'Setting lock' Write-Output 'Setting lock'
$lock = $true
$timeout = 10
$i = 0
while ($lock) {
if ($env:temp) { if ($env:temp) {
$lockFile = Join-Path -Path $env:temp -ChildPath 'lockfile_pubg.lock' $lockFile = Join-Path -Path $env:temp -ChildPath 'lockfile_pubg.lock'
} }
@ -7,10 +11,19 @@ function new-lock {
$lockFile = "/tmp/lockfile_pubg.lock" $lockFile = "/tmp/lockfile_pubg.lock"
} }
if (Test-Path -Path $lockFile) { if (Test-Path -Path $lockFile) {
Write-Host "Job is already running." Write-Host "Job is already running. Sleeping 10 seconds"
Exit Start-Sleep -Seconds 10
}else{
$lock = $false
}
if($i -ge $timeout){
Write-Output "Timed out"
exit
}
$i++
} }
New-Item -ItemType File -Path $lockFile | Out-Null New-Item -ItemType File -Path $lockFile | Out-Null
} }
function remove-lock { function remove-lock {
Write-Output 'Removing lock' Write-Output 'Removing lock'