Skip to content

Commit 1f42db0

Browse files
committed
timer tweaks
1 parent 6185889 commit 1f42db0

File tree

2 files changed

+59
-16
lines changed

2 files changed

+59
-16
lines changed

CIPPTimers.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[
22
{
3+
"Id": "c0c48d71-7918-4828-bc25-0e8c28a171a2",
34
"Command": "Start-DurableCleanup",
45
"Description": "Timer function to cleanup durable functions",
56
"Cron": "0 */15 * * * *",
@@ -8,6 +9,7 @@
89
"IsSystem": true
910
},
1011
{
12+
"Id": "76dc2e2e-eb89-47f7-bd9f-8aaebfe854c7",
1113
"Command": "Start-UserTasksOrchestrator",
1214
"Description": "Orchestrator to process user scheduled tasks",
1315
"Cron": "0 */15 * * * *",
@@ -16,13 +18,15 @@
1618
"PreferredProcessor": "usertasks"
1719
},
1820
{
21+
"Id": "168decf3-7ddd-471e-ab46-8b40be0f18ae",
1922
"Command": "Start-CIPPProcessorQueue",
2023
"Description": "Timer to handle user initiated tasks",
2124
"Cron": "0 */15 * * * *",
2225
"Priority": 1,
2326
"RunOnProcessor": true
2427
},
2528
{
29+
"Id": "44a40668-ed71-403c-8c26-b32e320086ad",
2630
"Command": "Start-AuditLogOrchestrator",
2731
"Description": "Orchestrator to process audit logs",
2832
"Cron": "0 */15 * * * *",
@@ -32,6 +36,7 @@
3236
"IsSystem": true
3337
},
3438
{
39+
"Id": "03475c86-4314-4d7b-90f2-5a0639e3899b",
3540
"Command": "Start-AuditLogSearchCreation",
3641
"Description": "Timer to create audit log searches",
3742
"Cron": "0 */30 * * * *",
@@ -41,20 +46,23 @@
4146
"IsSystem": true
4247
},
4348
{
49+
"Id": "5ff6c500-e420-4a3b-8532-ace2e4da4f7d",
4450
"Command": "Start-ApplicationOrchestrator",
4551
"Description": "Orchestrator to process application uploads",
4652
"Cron": "0 0 */12 * * *",
4753
"Priority": 2,
4854
"RunOnProcessor": true
4955
},
5056
{
57+
"Id": "5b3bb926-d107-471e-8787-3b22b0d4dbbe",
5158
"Command": "Start-WebhookOrchestrator",
5259
"Description": "Orchestrator to process webhooks",
5360
"Cron": "0 */15 * * * *",
5461
"Priority": 3,
5562
"RunOnProcessor": true
5663
},
5764
{
65+
"Id": "9b0c8e50-f798-49db-9a8b-dbcc0fcadeea",
5866
"Command": "Start-StandardsOrchestrator",
5967
"Description": "Orchestrator to process standards",
6068
"Cron": "0 0 */4 * * *",
@@ -63,27 +71,31 @@
6371
"PreferredProcessor": "standards"
6472
},
6573
{
74+
"Id": "5113c66d-c040-42df-9565-39dff90ddd55",
6675
"Command": "Start-CIPPGraphSubscriptionCleanupTimer",
6776
"Description": "Orchestrator to cleanup old Graph subscriptions",
6877
"Cron": "0 0 0 * * *",
6978
"Priority": 5,
7079
"RunOnProcessor": true
7180
},
7281
{
82+
"Id": "97145a1d-28f0-4bb2-b929-5a43517d23cc",
7383
"Command": "Start-SchedulerOrchestrator",
7484
"Description": "Orchestrator to process system scheduled tasks",
7585
"Cron": "0 0 * * * *",
7686
"Priority": 6,
7787
"RunOnProcessor": true
7888
},
7989
{
90+
"Id": "ed7b5241-1cb9-499b-8f5b-1013ba5764b4",
8091
"Command": "Set-CIPPGDAPInviteGroups",
8192
"Description": "Orchestrator to map the groups for GDAP invites",
8293
"Cron": "0 0 */3 * * *",
8394
"Priority": 5,
8495
"RunOnProcessor": true
8596
},
8697
{
98+
"Id": "4ca242d0-8dc8-4256-b0ed-186599f4233f",
8799
"Command": "Start-UpdateTokensTimer",
88100
"Description": "Orchestrator to update tokens",
89101
"Cron": "0 0 0 * * 0",
@@ -92,6 +104,7 @@
92104
"IsSystem": true
93105
},
94106
{
107+
"Id": "ebe981b6-4417-406e-a1a5-7b8279058841",
95108
"Command": "Start-CIPPGraphSubscriptionRenewalTimer",
96109
"Description": "Orchestrator to renew Graph subscriptions",
97110
"Cron": "0 15 * * * *",
@@ -100,13 +113,15 @@
100113
"IsSystem": true
101114
},
102115
{
116+
"Id": "c2ebde3f-fa35-45aa-8a6b-91c835050b79",
103117
"Command": "Start-DomainOrchestrator",
104118
"Description": "Orchestrator to process domains",
105119
"Cron": "0 0 0 * * *",
106120
"Priority": 10,
107121
"RunOnProcessor": true
108122
},
109123
{
124+
"Id": "f82345da-e370-4b15-8167-be148cfd04af",
110125
"Command": "Get-Tenants",
111126
"Parameters": {
112127
"TriggerRefresh": true
@@ -118,6 +133,7 @@
118133
"IsSystem": true
119134
},
120135
{
136+
"Id": "d9ff3af4-bd34-40d6-b12a-8fa24463f331",
121137
"Command": "Start-UpdatePermissionsOrchestrator",
122138
"Description": "Orchestrator to update CPV permissions",
123139
"Cron": "0 0 0 * * *",
@@ -126,27 +142,31 @@
126142
"IsSystem": true
127143
},
128144
{
145+
"Id": "467787cf-01c5-4d20-8097-c2eef691a20e",
129146
"Command": "Start-BillingTimer",
130147
"Description": "Timer to process billing",
131148
"Cron": "0 0 0 * * *",
132149
"Priority": 12,
133150
"RunOnProcessor": true
134151
},
135152
{
153+
"Id": "80070b4f-95ed-4e5f-be4c-9e339306d4aa",
136154
"Command": "Start-BPAOrchestrator",
137155
"Description": "Orchestrator to process BPA reports",
138156
"Cron": "0 0 3 * * *",
139157
"Priority": 10,
140158
"RunOnProcessor": true
141159
},
142160
{
161+
"Id": "54c39540-fe91-4795-8613-ac4295751a51",
143162
"Command": "Start-ExtensionOrchestrator",
144163
"Description": "Orchestrator to process extensions",
145164
"Cron": "0 0 */2 * * *",
146165
"Priority": 12,
147166
"RunOnProcessor": true
148167
},
149168
{
169+
"Id": "3fb9745b-08c9-411b-bfac-dc48087489d5",
150170
"Command": "Start-CIPPStatsTimer",
151171
"Description": "Timer to process CIPP stats",
152172
"Cron": "0 0 0 * * *",
@@ -155,6 +175,7 @@
155175
"IsSystem": true
156176
},
157177
{
178+
"Id": "f74a4540-c811-4037-997c-0d32d7d5742f",
158179
"Command": "Start-TableCleanup",
159180
"Description": "Timer to cleanup tables",
160181
"Cron": "0 0 23 * * *",
@@ -163,6 +184,7 @@
163184
"IsSystem": true
164185
},
165186
{
187+
"Id": "e87db59d-3386-4a51-8274-da9aeb6793e3",
166188
"Command": "Get-Tenants",
167189
"Parameters": {
168190
"CleanOld": true

Modules/CIPPCore/Public/Get-CIPPTimerFunctions.ps1

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function Get-CIPPTimerFunctions {
22
[CmdletBinding()]
33
param(
4-
[switch]$All,
5-
[switch]$ResetToDefault
4+
[switch]$ResetToDefault,
5+
[switch]$ListAllTasks
66
)
77

88
$ConfigTable = Get-CIPPTable -tablename Config
@@ -23,7 +23,7 @@ function Get-CIPPTimerFunctions {
2323

2424
$RunOnProcessor = $true
2525
if ($Config -and $Config.state -eq $true) {
26-
if ($env:CIPP_PROCESSOR -ne 'true' -and !$All.IsPresent) {
26+
if ($env:CIPP_PROCESSOR -ne 'true') {
2727
$RunOnProcessor = $false
2828
}
2929
}
@@ -38,12 +38,29 @@ function Get-CIPPTimerFunctions {
3838
}
3939

4040
$CIPPRoot = (Get-Item $CIPPCoreModuleRoot).Parent.Parent
41-
$Orchestrators = Get-Content -Path $CIPPRoot\CIPPTimers.json | ConvertFrom-Json | Where-Object { $_.RunOnProcessor -eq $RunOnProcessor } | Sort-Object -Property Priority
41+
$CippTimers = Get-Content -Path $CIPPRoot\CIPPTimers.json
42+
if ($ListAllTasks) {
43+
$Orchestrators = $CippTimers | ConvertFrom-Json | Sort-Object -Property Priority
44+
} else {
45+
$Orchestrators = $CippTimers | ConvertFrom-Json | Where-Object { $_.RunOnProcessor -eq $RunOnProcessor } | Sort-Object -Property Priority
46+
}
4247
$Table = Get-CIPPTable -TableName 'CIPPTimers'
4348
$RunOnProcessorTxt = if ($RunOnProcessor) { 'true' } else { 'false' }
44-
$OrchestratorStatus = Get-CIPPAzDataTableEntity @Table -Filter "RunOnProcessor eq $RunOnProcessorTxt"
49+
if ($ListAllTasks.IsPresent) {
50+
$OrchestratorStatus = Get-CIPPAzDataTableEntity @Table
51+
} else {
52+
$OrchestratorStatus = Get-CIPPAzDataTableEntity @Table -Filter "RunOnProcessor eq $RunOnProcessorTxt"
53+
}
54+
55+
Write-Host ($OrchestratorStatus | ConvertTo-Json)
56+
57+
$OrchestratorStatus | Where-Object { $_.RowKey -notmatch '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' } | Select-Object ETag, PartitionKey, RowKey | ForEach-Object {
58+
Remove-AzDataTableEntity @Table -Entity $_ -Force
59+
}
60+
61+
4562
foreach ($Orchestrator in $Orchestrators) {
46-
$Status = $OrchestratorStatus | Where-Object { $_.RowKey -eq $Orchestrator.Command }
63+
$Status = $OrchestratorStatus | Where-Object { $_.RowKey -eq $Orchestrator.Id }
4764
if ($Status.Cron) {
4865
$CronString = $Status.Cron
4966
} else {
@@ -59,16 +76,18 @@ function Get-CIPPTimerFunctions {
5976
continue
6077
}
6178

62-
if ($Orchestrator.PreferredProcessor -and $AvailableNodes -contains $Orchestrator.PreferredProcessor -and $Node -ne $Orchestrator.PreferredProcessor) {
63-
# only run on preferred processor when available
64-
continue
65-
} elseif ((!$Orchestrator.PreferredProcessor -or $AvailableNodes -notcontains $Orchestrator.PreferredProcessor) -and $Node -notin ('http', 'proc')) {
66-
# Catchall function nodes
67-
continue
79+
if (!$ListAllTasks.IsPresent) {
80+
if ($Orchestrator.PreferredProcessor -and $AvailableNodes -contains $Orchestrator.PreferredProcessor -and $Node -ne $Orchestrator.PreferredProcessor) {
81+
# only run on preferred processor when available
82+
continue
83+
} elseif ((!$Orchestrator.PreferredProcessor -or $AvailableNodes -notcontains $Orchestrator.PreferredProcessor) -and $Node -notin ('http', 'proc')) {
84+
# Catchall function nodes
85+
continue
86+
}
6887
}
6988

7089
$Now = Get-Date
71-
if ($All.IsPresent) {
90+
if ($ListAllTasks.IsPresent) {
7291
$NextOccurrence = [datetime]$Cron.GetNextOccurrence($Now)
7392
} else {
7493
$NextOccurrences = $Cron.GetNextOccurrences($Now.AddMinutes(-15), $Now.AddMinutes(15))
@@ -80,11 +99,12 @@ function Get-CIPPTimerFunctions {
8099
}
81100

82101
if (Get-Command -Name $Orchestrator.Command -Module CIPPCore -ErrorAction SilentlyContinue) {
83-
if ($NextOccurrence) {
102+
if ($NextOccurrence -or $ListAllTasks.IsPresent) {
84103
if (!$Status) {
85104
$Status = [pscustomobject]@{
86105
PartitionKey = 'Timer'
87-
RowKey = $Orchestrator.Command
106+
RowKey = $Orchestrator.Id
107+
Command = $Orchestrator.Command
88108
Cron = $CronString
89109
LastOccurrence = 'Never'
90110
NextOccurrence = $NextOccurrence.ToUniversalTime()
@@ -94,7 +114,7 @@ function Get-CIPPTimerFunctions {
94114
IsSystem = $Orchestrator.IsSystem ?? $false
95115
PreferredProcessor = $Orchestrator.PreferredProcessor ?? ''
96116
}
97-
Add-CIPPAzDataTableEntity @Table -Entity $Status
117+
Add-CIPPAzDataTableEntity @Table -Entity $Status -Force
98118
} else {
99119
if ($Orchestrator.IsSystem -eq $true -or $ResetToDefault.IsPresent) {
100120
$Status.Cron = $CronString
@@ -110,6 +130,7 @@ function Get-CIPPTimerFunctions {
110130
}
111131

112132
[PSCustomObject]@{
133+
Id = $Orchestrator.Id
113134
Priority = $Orchestrator.Priority
114135
Command = $Orchestrator.Command
115136
Parameters = $Orchestrator.Parameters ?? @{}

0 commit comments

Comments
 (0)