-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathworkflow-counts.ts
More file actions
94 lines (87 loc) · 2.37 KB
/
workflow-counts.ts
File metadata and controls
94 lines (87 loc) · 2.37 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
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
89
90
91
92
93
94
import type { CountWorkflowExecutionsResponse } from '$lib/types/workflows';
import { DataClient } from '$lib/utilities/api/fetch';
import { requestFromAPI } from '$lib/utilities/request-from-api';
import { routeForApi } from '$lib/utilities/route-for-api';
export const fetchWorkflowCount = async (
namespace: string,
query: string,
request = fetch,
): Promise<{ count: number }> => {
let count = 0;
try {
const countRoute = routeForApi('workflows.count', { namespace });
const result = await requestFromAPI<{ count: string }>(countRoute, {
params: query ? { query } : {},
onError: () => {},
handleError: () => {},
request,
});
count = parseInt(result?.count || '0');
} catch (e) {
// Don't fail the workflows call due to count
}
return { count };
};
type WorkflowCountByExecutionStatusOptions = {
namespace: string;
query: string;
};
export const fetchWorkflowCountByExecutionStatus = async ({
namespace,
query,
}: WorkflowCountByExecutionStatusOptions): Promise<CountWorkflowExecutionsResponse> => {
const groupByClause = 'GROUP BY ExecutionStatus';
return DataClient.GET('/api/v1/namespaces/{namespace}/workflow-count', {
params: {
path: {
namespace,
},
query: {
query,
},
},
})
.then((data) => {
return data.data;
})
.then((data) => {
return { count: data.count, groups };
});
const countRoute = routeForApi('workflows.count', {
namespace,
});
const { count, groups } =
await requestFromAPI<CountWorkflowExecutionsResponse>(countRoute, {
params: {
query: query ? `${query} ${groupByClause}` : `${groupByClause}`,
},
notifyOnError: false,
});
return { count: count ?? '0', groups };
};
export const fetchScheduleCount = async ({
namespace,
query,
}: {
namespace: string;
query?: string;
}): Promise<string> => {
const scheduleFixedQuery =
'TemporalNamespaceDivision="TemporalScheduler" AND ExecutionStatus="Running"';
const fullQuery = query
? `${scheduleFixedQuery} AND ${query}`
: scheduleFixedQuery;
const countRoute = routeForApi('workflows.count', {
namespace,
});
const { count } = await requestFromAPI<CountWorkflowExecutionsResponse>(
countRoute,
{
params: {
query: fullQuery,
},
notifyOnError: false,
},
);
return count ?? '0';
};