@@ -107,12 +107,32 @@ function Push-ExecScheduledCommand {
107107 } catch {
108108 Write-Host " Failed to run task: $ ( $_.Exception.Message ) "
109109 $errorMessage = $_.Exception.Message
110+ # if recurrence is just a number, add it in days.
111+ if ($task.Recurrence -match ' ^\d+$' ) {
112+ $task.Recurrence = $task.Recurrence + ' d'
113+ }
114+ $secondsToAdd = switch - Regex ($task.Recurrence ) {
115+ ' (\d+)m$' { [int64 ]$matches [1 ] * 60 }
116+ ' (\d+)h$' { [int64 ]$matches [1 ] * 3600 }
117+ ' (\d+)d$' { [int64 ]$matches [1 ] * 86400 }
118+ default { 0 }
119+ }
120+
121+ if ($secondsToAdd -gt 0 ) {
122+ $unixtimeNow = [int64 ](([datetime ]::UtcNow) - (Get-Date ' 1/1/1970' )).TotalSeconds
123+ if ([int64 ]$task.ScheduledTime -lt ($unixtimeNow - $secondsToAdd )) {
124+ $task.ScheduledTime = $unixtimeNow
125+ }
126+ }
127+
128+ $nextRunUnixTime = [int64 ]$task.ScheduledTime + [int64 ]$secondsToAdd
110129 if ($task.Recurrence -ne 0 ) { $State = ' Failed - Planned' } else { $State = ' Failed' }
111130 Update-AzDataTableEntity - Force @Table - Entity @ {
112- PartitionKey = $task.PartitionKey
113- RowKey = $task.RowKey
114- Results = " $errorMessage "
115- TaskState = $State
131+ PartitionKey = $task.PartitionKey
132+ RowKey = $task.RowKey
133+ Results = " $errorMessage "
134+ ScheduledTime = " $nextRunUnixTime "
135+ TaskState = $State
116136 }
117137 Write-LogMessage - API ' Scheduler_UserTasks' - tenant $Tenant - tenantid $TenantInfo.customerId - message " Failed to execute task $ ( $task.Name ) : $errorMessage " - sev Error - LogData (Get-CippExceptionData - Exception $_.Exception )
118138 }
0 commit comments