Skip to content

Commit 445df4a

Browse files
committed
fix: check current state before running task
1 parent 7765d81 commit 445df4a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ function Push-ExecScheduledCommand {
1818
# We don't need to expand groups here as that's handled in the orchestrator
1919
$TenantInfo = Get-Tenants -TenantFilter $Tenant
2020

21+
$CurrentTask = Get-AzDataTableEntity @Table -Filter "PartitionKey eq '$($task.PartitionKey)' and RowKey eq '$($task.RowKey)'"
22+
if (!$CurrentTask) {
23+
Write-Information "The task $($task.Name) for tenant $($task.Tenant) does not exist in the ScheduledTasks table. Exiting."
24+
return
25+
}
26+
if ($CurrentTask.TaskState -eq 'Completed') {
27+
Write-Information "The task $($task.Name) for tenant $($task.Tenant) is already completed. Skipping execution."
28+
return
29+
}
30+
2131
if ($task.Trigger) {
2232
# Extract trigger data from the task and process
2333
$Trigger = if (Test-Json -Json $task.Trigger) { $task.Trigger | ConvertFrom-Json } else { $task.Trigger }
@@ -276,7 +286,7 @@ function Push-ExecScheduledCommand {
276286
Write-Information 'Sent the results to the target. Updating the task state.'
277287

278288
try {
279-
if ($task.Recurrence -eq '0' -or [string]::IsNullOrEmpty($task.Recurrence) -or $Trigger.ExecutionMode.value -eq 'once') {
289+
if ($task.Recurrence -eq '0' -or [string]::IsNullOrEmpty($task.Recurrence) -or $Trigger.ExecutionMode.value -eq 'once' -or $Trigger.ExecutionMode -eq 'once') {
280290
Write-Information 'Recurrence empty or 0. Task is not recurring. Setting task state to completed.'
281291
Update-AzDataTableEntity -Force @Table -Entity @{
282292
PartitionKey = $task.PartitionKey

0 commit comments

Comments
 (0)