@@ -180,6 +180,7 @@ function Receive-CippOrchestrationTrigger {
180180 }
181181 Write-Information " Orchestrator started $ ( $OrchestratorInput.OrchestratorName ) "
182182 Write-Warning " Receive-CippOrchestrationTrigger - $ ( $OrchestratorInput.OrchestratorName ) "
183+ Set-DurableCustomStatus - CustomStatus $OrchestratorInput.OrchestratorName
183184 $DurableRetryOptions = @ {
184185 FirstRetryInterval = (New-TimeSpan - Seconds 5 )
185186 MaxNumberOfAttempts = if ($OrchestratorInput.MaxAttempts ) { $OrchestratorInput.MaxAttempts } else { 1 }
@@ -203,20 +204,15 @@ function Receive-CippOrchestrationTrigger {
203204 Write-Information " Durable Mode: $DurableMode "
204205
205206 $RetryOptions = New-DurableRetryOptions @DurableRetryOptions
206-
207- if ($Context.IsReplaying -ne $true -and $OrchestratorInput.SkipLog -ne $true ) {
208- Write-LogMessage - API $OrchestratorInput.OrchestratorName - tenant $OrchestratorInput.TenantFilter - message " Started $ ( $OrchestratorInput.OrchestratorName ) " - sev info
209- }
210-
211207 if (! $OrchestratorInput.Batch -or ($OrchestratorInput.Batch | Measure-Object ).Count -eq 0 ) {
212- $Batch = (Invoke-ActivityFunction - FunctionName ' CIPPActivityFunction' - Input $OrchestratorInput.QueueFunction - ErrorAction Stop)
208+ $Batch = (Invoke-ActivityFunction - FunctionName ' CIPPActivityFunction' - Input $OrchestratorInput.QueueFunction - ErrorAction Stop) | Where-Object { $null -ne $_ .FunctionName }
213209 } else {
214- $Batch = $OrchestratorInput.Batch
210+ $Batch = $OrchestratorInput.Batch | Where-Object { $null -ne $_ .FunctionName }
215211 }
216212
217213 if (($Batch | Measure-Object ).Count -gt 0 ) {
218214 Write-Information " Batch Count: $ ( $Batch.Count ) "
219- $Tasks = foreach ($Item in $Batch ) {
215+ $Output = foreach ($Item in $Batch ) {
220216 $DurableActivity = @ {
221217 FunctionName = ' CIPPActivityFunction'
222218 Input = $Item
@@ -226,13 +222,34 @@ function Receive-CippOrchestrationTrigger {
226222 }
227223 Invoke-DurableActivity @DurableActivity
228224 }
229- if ($NoWait -and $Tasks ) {
230- $null = Wait-ActivityFunction - Task $Tasks
225+
226+ if ($NoWait -and $Output ) {
227+ $Output = $Output | Where-Object { $_.GetType ().Name -eq ' ActivityInvocationTask' }
228+ if (($Output | Measure-Object ).Count -gt 0 ) {
229+ Write-Information " Waiting for ($ ( $Output.Count ) ) activity functions to complete..."
230+ $Results = Wait-ActivityFunction - Task @ ($Output )
231+ } else {
232+ $Results = @ ()
233+ }
234+ } else {
235+ $Results = $Output
231236 }
232237 }
233238
234- if ($Context.IsReplaying -ne $true -and $OrchestratorInput.SkipLog -ne $true ) {
235- Write-LogMessage - API $OrchestratorInput.OrchestratorName - tenant $tenant - message " Finished $ ( $OrchestratorInput.OrchestratorName ) " - sev Info
239+ if ($Results -and $OrchestratorInput.PostExecution ) {
240+ Write-Information " Running post execution function $ ( $OrchestratorInput.PostExecution.FunctionName ) "
241+ $PostExecParams = @ {
242+ FunctionName = $OrchestratorInput.PostExecution.FunctionName
243+ Parameters = $OrchestratorInput.PostExecution.Parameters
244+ Results = @ ($Results )
245+ }
246+ if ($null -ne $PostExecParams.FunctionName ) {
247+ $null = Invoke-ActivityFunction - FunctionName CIPPActivityFunction - Input $PostExecParams
248+ Write-Information " Post execution function $ ( $OrchestratorInput.PostExecution.FunctionName ) completed"
249+ } else {
250+ Write-Information ' No post execution function name provided'
251+ Write-Information ($PostExecParams | ConvertTo-Json - Depth 10 )
252+ }
236253 }
237254 } catch {
238255 Write-Information " Orchestrator error $ ( $_.Exception.Message ) line $ ( $_.InvocationInfo.ScriptLineNumber ) "
@@ -322,11 +339,11 @@ function Receive-CippActivityTrigger {
322339 }
323340 }
324341
325- # Return the captured output if it exists and is not null, otherwise return $true
342+ # Return the captured output if it exists and is not null
326343 if ($null -ne $Output -and $Output -ne ' ' ) {
327344 return $Output
328345 } else {
329- return $true
346+ return
330347 }
331348}
332349
0 commit comments