@@ -271,7 +271,6 @@ function Receive-CippActivityTrigger {
271271 param ($Item )
272272 Write-Warning " Hey Boo, the activity function is running. Here's some info: $ ( $Item | ConvertTo-Json - Depth 10 - Compress) "
273273 try {
274- $Start = Get-Date
275274 $Output = $null
276275 Set-Location (Get-Item $PSScriptRoot ).Parent.Parent.FullName
277276
@@ -294,14 +293,14 @@ function Receive-CippActivityTrigger {
294293
295294 if ($Item.FunctionName ) {
296295 $FunctionName = ' Push-{0}' -f $Item.FunctionName
297-
296+
298297 # Prepare telemetry metadata
299298 $taskName = if ($Item.Command ) { $Item.Command } else { $FunctionName }
300299 $metadata = @ {
301300 Command = if ($Item.Command ) { $Item.Command } else { $FunctionName }
302301 FunctionName = $FunctionName
303302 }
304-
303+
305304 # Add tenant information if available
306305 if ($Item.TaskInfo ) {
307306 if ($Item.TaskInfo.Tenant ) {
@@ -314,7 +313,7 @@ function Receive-CippActivityTrigger {
314313 $metadata [' Recurrence' ] = $Item.TaskInfo.Recurrence
315314 }
316315 }
317-
316+
318317 # Add tenant from other common fields
319318 if (-not $metadata [' Tenant' ]) {
320319 if ($Item.TenantFilter ) {
@@ -323,23 +322,23 @@ function Receive-CippActivityTrigger {
323322 $metadata [' Tenant' ] = $Item.Tenant
324323 }
325324 }
326-
325+
327326 # Add queue information
328327 if ($Item.QueueId ) {
329328 $metadata [' QueueId' ] = $Item.QueueId
330329 }
331330 if ($Item.QueueName ) {
332331 $metadata [' QueueName' ] = $Item.QueueName
333332 }
334-
333+
335334 try {
336335 Write-Warning " Activity starting Function: $FunctionName ."
337-
336+
338337 # Wrap the function execution with telemetry
339338 $Output = Measure-CippTask - TaskName $taskName - Metadata $metadata - Script {
340339 Invoke-Command - ScriptBlock { & $FunctionName - Item $Item }
341340 }
342-
341+
343342 Write-Warning " Activity completed Function: $FunctionName ."
344343 if ($TaskStatus ) {
345344 $QueueTask.Status = ' Completed'
@@ -349,6 +348,7 @@ function Receive-CippActivityTrigger {
349348 $ErrorMsg = $_.Exception.Message
350349 if ($TaskStatus ) {
351350 $QueueTask.Status = ' Failed'
351+ $QueueTask.Message = $ErrorMsg
352352 $null = Set-CippQueueTask @QueueTask
353353 }
354354 }
@@ -359,21 +359,6 @@ function Receive-CippActivityTrigger {
359359 $null = Set-CippQueueTask @QueueTask
360360 }
361361 }
362-
363- $End = Get-Date
364-
365- try {
366- $Stats = @ {
367- FunctionType = ' Durable'
368- Entity = $Item
369- Start = $Start
370- End = $End
371- ErrorMsg = $ErrorMsg
372- }
373- Write-CippFunctionStats @Stats
374- } catch {
375- Write-Information " Error adding activity stats: $ ( $_.Exception.Message ) "
376- }
377362 } catch {
378363 Write-Information " Error in Receive-CippActivityTrigger: $ ( $_.Exception.Message ) "
379364 if ($TaskStatus ) {
@@ -434,12 +419,12 @@ function Receive-CIPPTimerTrigger {
434419
435420 # Prepare telemetry metadata
436421 $metadata = @ {
437- Command = $Function.Command
438- Cron = $Function.Cron
439- FunctionId = $Function.Id
422+ Command = $Function.Command
423+ Cron = $Function.Cron
424+ FunctionId = $Function.Id
440425 TriggerType = ' Timer'
441426 }
442-
427+
443428 # Add parameters if available
444429 if ($Parameters.Count -gt 0 ) {
445430 $metadata [' ParameterCount' ] = $Parameters.Count
@@ -456,7 +441,7 @@ function Receive-CIPPTimerTrigger {
456441 $Results = Measure-CippTask - TaskName $Function.Command - Metadata $metadata - Script {
457442 Invoke-Command - ScriptBlock { & $Function.Command @Parameters }
458443 }
459-
444+
460445 if ($Results -match ' ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' ) {
461446 $FunctionStatus.OrchestratorId = $Results -join ' ,'
462447 $Status = ' Started'
0 commit comments