Skip to content

Commit 468bc8c

Browse files
authored
Merge pull request KelvinTegelaar#1073 from JohnDuprey/dev
Fix for scheduled time in the past
2 parents 2f74278 + b52d009 commit 468bc8c

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

Modules/CIPPCore/Public/Add-CIPPScheduledTask.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ function Add-CIPPScheduledTask {
5151
$task.Recurrence.value
5252
}
5353

54+
if ([int64]$task.ScheduledTime -eq 0 -or [string]::IsNullOrEmpty($task.ScheduledTime)) {
55+
$task.ScheduledTime = [int64](([datetime]::UtcNow) - (Get-Date '1/1/1970')).TotalSeconds
56+
}
57+
5458
$entity = @{
5559
PartitionKey = [string]'ScheduledTask'
5660
TaskState = [string]'Planned'

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ function Push-ExecScheduledCommand {
100100
'(\d+)d$' { [int64]$matches[1] * 86400 }
101101
default { throw "Unsupported recurrence format: $($task.Recurrence)" }
102102
}
103+
104+
if ($secondsToAdd -gt 0) {
105+
$unixtimeNow = [int64](([datetime]::UtcNow) - (Get-Date '1/1/1970')).TotalSeconds
106+
if ([int64]$task.ScheduledTime -lt ($unixtimeNow - $secondsToAdd)) {
107+
$task.ScheduledTime = $unixtimeNow
108+
}
109+
}
110+
103111
$nextRunUnixTime = [int64]$task.ScheduledTime + [int64]$secondsToAdd
104112
Write-Host "The job is recurring. It was scheduled for $($task.ScheduledTime). The next runtime should be $nextRunUnixTime"
105113
Update-AzDataTableEntity @Table -Entity @{

0 commit comments

Comments
 (0)