This repository was archived by the owner on Mar 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathTimerComparer.cs
More file actions
57 lines (44 loc) · 1.77 KB
/
TimerComparer.cs
File metadata and controls
57 lines (44 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using NuGet.Insights.Worker.AuxiliaryFileUpdater;
using NuGet.Insights.Worker.KustoIngestion;
using NuGet.Insights.Worker.ReferenceTracking;
using NuGet.Insights.Worker.TimedReprocess;
using NuGet.Insights.Worker.Workflow;
namespace NuGet.Insights.Worker
{
public class TimerComparer : IComparer<ITimer>
{
public static TimerComparer Instance { get; } = new TimerComparer();
private static readonly ConcurrentDictionary<Type, int> TypeCache = new();
private static readonly IReadOnlyList<Func<Type, bool>> DesiredGrouping = new Func<Type, bool>[]
{
x => x.IsAssignableTo(typeof(WorkflowTimer)),
x => x.IsAssignableTo(typeof(TimedReprocessTimer)),
x => x.IsAssignableTo(typeof(CatalogScanUpdateTimer)),
x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(CleanupOrphanRecordsTimer<>),
x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(AuxiliaryFileUpdaterTimer<,>),
x => x.IsAssignableTo(typeof(KustoIngestionTimer)),
};
public int Compare(ITimer x, ITimer y)
{
return GetIndex(x).CompareTo(GetIndex(y));
}
private int GetIndex(ITimer x)
{
return TypeCache.GetOrAdd(x.GetType(), type =>
{
var i = 0;
foreach (var predicate in DesiredGrouping)
{
if (predicate(type))
{
return i;
}
i++;
}
return i;
});
}
}
}