Skip to content

Commit

Permalink
timer tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnDuprey committed Jan 10, 2025
1 parent 6185889 commit 1f42db0
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 16 deletions.
22 changes: 22 additions & 0 deletions CIPPTimers.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
{
"Id": "c0c48d71-7918-4828-bc25-0e8c28a171a2",
"Command": "Start-DurableCleanup",
"Description": "Timer function to cleanup durable functions",
"Cron": "0 */15 * * * *",
Expand All @@ -8,6 +9,7 @@
"IsSystem": true
},
{
"Id": "76dc2e2e-eb89-47f7-bd9f-8aaebfe854c7",
"Command": "Start-UserTasksOrchestrator",
"Description": "Orchestrator to process user scheduled tasks",
"Cron": "0 */15 * * * *",
Expand All @@ -16,13 +18,15 @@
"PreferredProcessor": "usertasks"
},
{
"Id": "168decf3-7ddd-471e-ab46-8b40be0f18ae",
"Command": "Start-CIPPProcessorQueue",
"Description": "Timer to handle user initiated tasks",
"Cron": "0 */15 * * * *",
"Priority": 1,
"RunOnProcessor": true
},
{
"Id": "44a40668-ed71-403c-8c26-b32e320086ad",
"Command": "Start-AuditLogOrchestrator",
"Description": "Orchestrator to process audit logs",
"Cron": "0 */15 * * * *",
Expand All @@ -32,6 +36,7 @@
"IsSystem": true
},
{
"Id": "03475c86-4314-4d7b-90f2-5a0639e3899b",
"Command": "Start-AuditLogSearchCreation",
"Description": "Timer to create audit log searches",
"Cron": "0 */30 * * * *",
Expand All @@ -41,20 +46,23 @@
"IsSystem": true
},
{
"Id": "5ff6c500-e420-4a3b-8532-ace2e4da4f7d",
"Command": "Start-ApplicationOrchestrator",
"Description": "Orchestrator to process application uploads",
"Cron": "0 0 */12 * * *",
"Priority": 2,
"RunOnProcessor": true
},
{
"Id": "5b3bb926-d107-471e-8787-3b22b0d4dbbe",
"Command": "Start-WebhookOrchestrator",
"Description": "Orchestrator to process webhooks",
"Cron": "0 */15 * * * *",
"Priority": 3,
"RunOnProcessor": true
},
{
"Id": "9b0c8e50-f798-49db-9a8b-dbcc0fcadeea",
"Command": "Start-StandardsOrchestrator",
"Description": "Orchestrator to process standards",
"Cron": "0 0 */4 * * *",
Expand All @@ -63,27 +71,31 @@
"PreferredProcessor": "standards"
},
{
"Id": "5113c66d-c040-42df-9565-39dff90ddd55",
"Command": "Start-CIPPGraphSubscriptionCleanupTimer",
"Description": "Orchestrator to cleanup old Graph subscriptions",
"Cron": "0 0 0 * * *",
"Priority": 5,
"RunOnProcessor": true
},
{
"Id": "97145a1d-28f0-4bb2-b929-5a43517d23cc",
"Command": "Start-SchedulerOrchestrator",
"Description": "Orchestrator to process system scheduled tasks",
"Cron": "0 0 * * * *",
"Priority": 6,
"RunOnProcessor": true
},
{
"Id": "ed7b5241-1cb9-499b-8f5b-1013ba5764b4",
"Command": "Set-CIPPGDAPInviteGroups",
"Description": "Orchestrator to map the groups for GDAP invites",
"Cron": "0 0 */3 * * *",
"Priority": 5,
"RunOnProcessor": true
},
{
"Id": "4ca242d0-8dc8-4256-b0ed-186599f4233f",
"Command": "Start-UpdateTokensTimer",
"Description": "Orchestrator to update tokens",
"Cron": "0 0 0 * * 0",
Expand All @@ -92,6 +104,7 @@
"IsSystem": true
},
{
"Id": "ebe981b6-4417-406e-a1a5-7b8279058841",
"Command": "Start-CIPPGraphSubscriptionRenewalTimer",
"Description": "Orchestrator to renew Graph subscriptions",
"Cron": "0 15 * * * *",
Expand All @@ -100,13 +113,15 @@
"IsSystem": true
},
{
"Id": "c2ebde3f-fa35-45aa-8a6b-91c835050b79",
"Command": "Start-DomainOrchestrator",
"Description": "Orchestrator to process domains",
"Cron": "0 0 0 * * *",
"Priority": 10,
"RunOnProcessor": true
},
{
"Id": "f82345da-e370-4b15-8167-be148cfd04af",
"Command": "Get-Tenants",
"Parameters": {
"TriggerRefresh": true
Expand All @@ -118,6 +133,7 @@
"IsSystem": true
},
{
"Id": "d9ff3af4-bd34-40d6-b12a-8fa24463f331",
"Command": "Start-UpdatePermissionsOrchestrator",
"Description": "Orchestrator to update CPV permissions",
"Cron": "0 0 0 * * *",
Expand All @@ -126,27 +142,31 @@
"IsSystem": true
},
{
"Id": "467787cf-01c5-4d20-8097-c2eef691a20e",
"Command": "Start-BillingTimer",
"Description": "Timer to process billing",
"Cron": "0 0 0 * * *",
"Priority": 12,
"RunOnProcessor": true
},
{
"Id": "80070b4f-95ed-4e5f-be4c-9e339306d4aa",
"Command": "Start-BPAOrchestrator",
"Description": "Orchestrator to process BPA reports",
"Cron": "0 0 3 * * *",
"Priority": 10,
"RunOnProcessor": true
},
{
"Id": "54c39540-fe91-4795-8613-ac4295751a51",
"Command": "Start-ExtensionOrchestrator",
"Description": "Orchestrator to process extensions",
"Cron": "0 0 */2 * * *",
"Priority": 12,
"RunOnProcessor": true
},
{
"Id": "3fb9745b-08c9-411b-bfac-dc48087489d5",
"Command": "Start-CIPPStatsTimer",
"Description": "Timer to process CIPP stats",
"Cron": "0 0 0 * * *",
Expand All @@ -155,6 +175,7 @@
"IsSystem": true
},
{
"Id": "f74a4540-c811-4037-997c-0d32d7d5742f",
"Command": "Start-TableCleanup",
"Description": "Timer to cleanup tables",
"Cron": "0 0 23 * * *",
Expand All @@ -163,6 +184,7 @@
"IsSystem": true
},
{
"Id": "e87db59d-3386-4a51-8274-da9aeb6793e3",
"Command": "Get-Tenants",
"Parameters": {
"CleanOld": true
Expand Down
53 changes: 37 additions & 16 deletions Modules/CIPPCore/Public/Get-CIPPTimerFunctions.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function Get-CIPPTimerFunctions {
[CmdletBinding()]
param(
[switch]$All,
[switch]$ResetToDefault
[switch]$ResetToDefault,
[switch]$ListAllTasks
)

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

$RunOnProcessor = $true
if ($Config -and $Config.state -eq $true) {
if ($env:CIPP_PROCESSOR -ne 'true' -and !$All.IsPresent) {
if ($env:CIPP_PROCESSOR -ne 'true') {
$RunOnProcessor = $false
}
}
Expand All @@ -38,12 +38,29 @@ function Get-CIPPTimerFunctions {
}

$CIPPRoot = (Get-Item $CIPPCoreModuleRoot).Parent.Parent
$Orchestrators = Get-Content -Path $CIPPRoot\CIPPTimers.json | ConvertFrom-Json | Where-Object { $_.RunOnProcessor -eq $RunOnProcessor } | Sort-Object -Property Priority
$CippTimers = Get-Content -Path $CIPPRoot\CIPPTimers.json
if ($ListAllTasks) {
$Orchestrators = $CippTimers | ConvertFrom-Json | Sort-Object -Property Priority
} else {
$Orchestrators = $CippTimers | ConvertFrom-Json | Where-Object { $_.RunOnProcessor -eq $RunOnProcessor } | Sort-Object -Property Priority
}
$Table = Get-CIPPTable -TableName 'CIPPTimers'
$RunOnProcessorTxt = if ($RunOnProcessor) { 'true' } else { 'false' }
$OrchestratorStatus = Get-CIPPAzDataTableEntity @Table -Filter "RunOnProcessor eq $RunOnProcessorTxt"
if ($ListAllTasks.IsPresent) {
$OrchestratorStatus = Get-CIPPAzDataTableEntity @Table
} else {
$OrchestratorStatus = Get-CIPPAzDataTableEntity @Table -Filter "RunOnProcessor eq $RunOnProcessorTxt"
}

Write-Host ($OrchestratorStatus | ConvertTo-Json)

$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 {
Remove-AzDataTableEntity @Table -Entity $_ -Force
}


foreach ($Orchestrator in $Orchestrators) {
$Status = $OrchestratorStatus | Where-Object { $_.RowKey -eq $Orchestrator.Command }
$Status = $OrchestratorStatus | Where-Object { $_.RowKey -eq $Orchestrator.Id }
if ($Status.Cron) {
$CronString = $Status.Cron
} else {
Expand All @@ -59,16 +76,18 @@ function Get-CIPPTimerFunctions {
continue
}

if ($Orchestrator.PreferredProcessor -and $AvailableNodes -contains $Orchestrator.PreferredProcessor -and $Node -ne $Orchestrator.PreferredProcessor) {
# only run on preferred processor when available
continue
} elseif ((!$Orchestrator.PreferredProcessor -or $AvailableNodes -notcontains $Orchestrator.PreferredProcessor) -and $Node -notin ('http', 'proc')) {
# Catchall function nodes
continue
if (!$ListAllTasks.IsPresent) {
if ($Orchestrator.PreferredProcessor -and $AvailableNodes -contains $Orchestrator.PreferredProcessor -and $Node -ne $Orchestrator.PreferredProcessor) {
# only run on preferred processor when available
continue
} elseif ((!$Orchestrator.PreferredProcessor -or $AvailableNodes -notcontains $Orchestrator.PreferredProcessor) -and $Node -notin ('http', 'proc')) {
# Catchall function nodes
continue
}
}

$Now = Get-Date
if ($All.IsPresent) {
if ($ListAllTasks.IsPresent) {
$NextOccurrence = [datetime]$Cron.GetNextOccurrence($Now)
} else {
$NextOccurrences = $Cron.GetNextOccurrences($Now.AddMinutes(-15), $Now.AddMinutes(15))
Expand All @@ -80,11 +99,12 @@ function Get-CIPPTimerFunctions {
}

if (Get-Command -Name $Orchestrator.Command -Module CIPPCore -ErrorAction SilentlyContinue) {
if ($NextOccurrence) {
if ($NextOccurrence -or $ListAllTasks.IsPresent) {
if (!$Status) {
$Status = [pscustomobject]@{
PartitionKey = 'Timer'
RowKey = $Orchestrator.Command
RowKey = $Orchestrator.Id
Command = $Orchestrator.Command
Cron = $CronString
LastOccurrence = 'Never'
NextOccurrence = $NextOccurrence.ToUniversalTime()
Expand All @@ -94,7 +114,7 @@ function Get-CIPPTimerFunctions {
IsSystem = $Orchestrator.IsSystem ?? $false
PreferredProcessor = $Orchestrator.PreferredProcessor ?? ''
}
Add-CIPPAzDataTableEntity @Table -Entity $Status
Add-CIPPAzDataTableEntity @Table -Entity $Status -Force
} else {
if ($Orchestrator.IsSystem -eq $true -or $ResetToDefault.IsPresent) {
$Status.Cron = $CronString
Expand All @@ -110,6 +130,7 @@ function Get-CIPPTimerFunctions {
}

[PSCustomObject]@{
Id = $Orchestrator.Id
Priority = $Orchestrator.Priority
Command = $Orchestrator.Command
Parameters = $Orchestrator.Parameters ?? @{}
Expand Down

0 comments on commit 1f42db0

Please sign in to comment.