-
Notifications
You must be signed in to change notification settings - Fork 0
/
WorkerCounter.cs
88 lines (75 loc) · 2.99 KB
/
WorkerCounter.cs
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System.Numerics;
public class WorkerCounter
{
private static Dictionary<String, Dictionary<String, BigInteger?>> perWorkflowIdDictionary =
new Dictionary<String, Dictionary<String, BigInteger?>>();
public static String NUM_OF_WORKFLOW_EXECUTIONS = "numOfWorkflowExec";
public static String NUM_OF_CHILD_WORKFLOW_EXECUTIONS = "numOfChildWorkflowExec";
public static String NUM_OF_ACTIVITY_EXECUTIONS = "numOfActivityExec";
public static String NUM_OF_SIGNALS = "numOfSignals";
public static String NUM_OF_QUERIES = "numOfQueries";
public static void Add(String workflowId, String type)
{
if (!perWorkflowIdDictionary.ContainsKey(workflowId))
{
perWorkflowIdDictionary.Add(workflowId, DefaultInfoMap());
}
if (perWorkflowIdDictionary[workflowId][type] == null)
{
perWorkflowIdDictionary[workflowId][type] = 1;
}
else
{
var current = perWorkflowIdDictionary[workflowId][type];
var next = current + 1;
perWorkflowIdDictionary[workflowId][type] = next;
}
}
public static BigInteger? NumOfWorkflowExecutions(String workflowId)
{
return perWorkflowIdDictionary[workflowId][NUM_OF_WORKFLOW_EXECUTIONS];
}
public static BigInteger? NumOfChildWorkflowExecutions(String workflowId)
{
return perWorkflowIdDictionary[workflowId][NUM_OF_CHILD_WORKFLOW_EXECUTIONS];
}
public static BigInteger? NumOfActivityExecutions(String workflowId)
{
return perWorkflowIdDictionary[workflowId][NUM_OF_ACTIVITY_EXECUTIONS];
}
public static BigInteger? NumOfSignals(String workflowId)
{
return perWorkflowIdDictionary[workflowId][NUM_OF_SIGNALS];
}
public static BigInteger? NumOfQueries(String workflowId)
{
return perWorkflowIdDictionary[workflowId][NUM_OF_QUERIES];
}
public static String Info()
{
String result = "";
foreach(var item in perWorkflowIdDictionary)
{
var info = item.Value;
result = result +
"\n** Workflow ID: " + item.Key +
"\n\tTotal Number of Workflow Exec: " + info[NUM_OF_WORKFLOW_EXECUTIONS] +
"\n\tTotal Number of Child Worflow Exec: " + info[NUM_OF_CHILD_WORKFLOW_EXECUTIONS] +
"\n\tTotal Number of Activity Exec: " + info[NUM_OF_ACTIVITY_EXECUTIONS] +
"\n\tTotal Number of Signals: " + info[NUM_OF_SIGNALS] +
"\n\tTotal Number of Queries: " + info[NUM_OF_QUERIES];
}
return result;
}
// Creates a default counter info map for a workflowid
private static Dictionary<String, BigInteger?> DefaultInfoMap() {
return new Dictionary<String, BigInteger?>()
{
{ NUM_OF_WORKFLOW_EXECUTIONS, 0 },
{ NUM_OF_CHILD_WORKFLOW_EXECUTIONS, 0 },
{ NUM_OF_ACTIVITY_EXECUTIONS, 0 },
{ NUM_OF_SIGNALS, 0},
{ NUM_OF_QUERIES, 0}
};
}
}