Skip to content

Commit b0cf055

Browse files
committed
Handle none-existing state file
1 parent 2331f2c commit b0cf055

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

watchdog.ps1

+6-7
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ function Test-RportState {
5151
.OUTPUTS
5252
System.ValueType Boolean
5353
#>
54-
if (-not (Test-Path $stateFile -PathType Leaf)) {
55-
Write-Message "ERROR: Statefile $($stateFile) not found. Not cheching."
56-
return
57-
}
5854
$now = [DateTimeOffset]::Now.ToUnixTimeSeconds()
5955
$lastUpdate = (Get-Content $stateFile | ConvertFrom-Json).last_update_ts
6056
$diff = $now - $lastUpdate
@@ -127,10 +123,10 @@ function Get-TaskState {
127123
if ($state) {
128124
Write-Output "Task $($taskName) is registered with state: $($state.state)"
129125
$taskInfo = (Get-ScheduledTaskInfo -TaskName $taskName)
130-
if($taskInfo.LastTaskResult -eq 267011) {
126+
if ($taskInfo.LastTaskResult -eq 267011) {
131127
Write-Output "Task has not yet run."
132128
}
133-
elif($taskInfo.LastTaskResult -ne 0){
129+
elif($taskInfo.LastTaskResult -ne 0) {
134130
Write-Output "**CAUTION! The last execution of the task has failed.**"
135131
}
136132
$taskInfo
@@ -198,7 +194,10 @@ if ($Register) {
198194

199195
# Wipe the logfile before each run
200196
Clear-Content $logFile -ErrorAction SilentlyContinue
201-
if (-not (Test-RportState)) {
197+
if (-not (Test-Path $stateFile -PathType Leaf)) {
198+
Write-Message "ERROR: Statefile $($stateFile) not found. Not checking."
199+
}
200+
elseif (-not (Test-RportState)) {
202201
Restart-Rport
203202
}
204203
if (-not (($env:USERPROFILE).Endswith("systemprofile"))) {

0 commit comments

Comments
 (0)