-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathworkflow-counts.ts
More file actions
115 lines (108 loc) · 3.36 KB
/
workflow-counts.ts
File metadata and controls
115 lines (108 loc) · 3.36 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import type {
CountSchedulesResponse,
CountWorkflowExecutionsResponse,
} from '$lib/types/workflows';
import { isNotFound, isNotImplemented } from '$lib/utilities/handle-error';
import { requestFromAPI } from '$lib/utilities/request-from-api';
import { routeForApi } from '$lib/utilities/route-for-api';
import { TASK_FAILURES_QUERY } from '$lib/utilities/workflow-task-failures';
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 {
// Don't fail the workflows call due to count
}
return { count };
};
export const fetchWorkflowTaskFailures = async (
namespace: string,
request = fetch,
): Promise<number> => {
try {
const countRoute = routeForApi('workflows.count', { namespace });
const result = await requestFromAPI<{ count: string }>(countRoute, {
params: { query: TASK_FAILURES_QUERY },
onError: () => {},
handleError: () => {},
request,
});
return parseInt(result?.count || '0');
} catch {
// Don't fail the workflows call due to count
}
};
type WorkflowCountByExecutionStatusOptions = {
namespace: string;
query: string;
};
export const fetchWorkflowCountByExecutionStatus = async ({
namespace,
query,
}: WorkflowCountByExecutionStatusOptions): Promise<CountWorkflowExecutionsResponse> => {
const groupByClause = 'GROUP BY ExecutionStatus';
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 };
};
// Uses the API in a private/unsupported way that will stop working in a future server release.
const fetchScheduleCountLegacy = async (
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';
};
export const fetchScheduleCount = async ({
namespace,
query,
}: {
namespace: string;
query?: string;
}): Promise<string> => {
return fetchScheduleCountLegacy(namespace, query);
// try {
// const countRoute = routeForApi('schedules.count', { namespace });
// const { count } = await requestFromAPI<CountSchedulesResponse>(countRoute, {
// params: query ? { query } : {},
// notifyOnError: false,
// });
// return count ?? '0';
// } catch (error: unknown) {
// if (isNotImplemented(error) || isNotFound(error)) {
// return fetchScheduleCountLegacy(namespace, query);
// }
// throw error;
// }
};