lock sleep and timeout
This commit is contained in:
parent
b77276f9fb
commit
98232ed7ef
1 changed files with 22 additions and 9 deletions
|
|
@ -1,16 +1,29 @@
|
||||||
function new-lock {
|
function new-lock {
|
||||||
Write-Output 'Setting lock'
|
Write-Output 'Setting lock'
|
||||||
if ($env:temp) {
|
$lock = $true
|
||||||
$lockFile = Join-Path -Path $env:temp -ChildPath 'lockfile_pubg.lock'
|
$timeout = 10
|
||||||
}
|
$i = 0
|
||||||
else {
|
while ($lock) {
|
||||||
$lockFile = "/tmp/lockfile_pubg.lock"
|
if ($env:temp) {
|
||||||
}
|
$lockFile = Join-Path -Path $env:temp -ChildPath 'lockfile_pubg.lock'
|
||||||
if (Test-Path -Path $lockFile) {
|
}
|
||||||
Write-Host "Job is already running."
|
else {
|
||||||
Exit
|
$lockFile = "/tmp/lockfile_pubg.lock"
|
||||||
|
}
|
||||||
|
if (Test-Path -Path $lockFile) {
|
||||||
|
Write-Host "Job is already running. Sleeping 10 seconds"
|
||||||
|
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'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue