github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/asynqmon/ui/src/actions/metricsActions.ts (about) 1 import { Dispatch } from "redux"; 2 import { getMetrics, MetricsResponse } from "../api"; 3 import { toErrorString, toErrorStringWithHttpStatus } from "../utils"; 4 5 // List of metrics related action types. 6 export const GET_METRICS_BEGIN = "GET_METRICS_BEGIN"; 7 export const GET_METRICS_SUCCESS = "GET_METRICS_SUCCESS"; 8 export const GET_METRICS_ERROR = "GET_METRICS_ERROR"; 9 10 interface GetMetricsBeginAction { 11 type: typeof GET_METRICS_BEGIN; 12 } 13 14 interface GetMetricsSuccessAction { 15 type: typeof GET_METRICS_SUCCESS; 16 payload: MetricsResponse; 17 } 18 19 interface GetMetricsErrorAction { 20 type: typeof GET_METRICS_ERROR; 21 error: string; 22 } 23 24 // Union of all metrics related actions. 25 export type MetricsActionTypes = 26 | GetMetricsBeginAction 27 | GetMetricsSuccessAction 28 | GetMetricsErrorAction; 29 30 export function getMetricsAsync( 31 endTime: number, 32 duration: number, 33 queues: string[] 34 ) { 35 return async (dispatch: Dispatch<MetricsActionTypes>) => { 36 dispatch({ type: GET_METRICS_BEGIN }); 37 try { 38 const response = await getMetrics(endTime, duration, queues); 39 dispatch({ type: GET_METRICS_SUCCESS, payload: response }); 40 } catch (error) { 41 console.error(`getMetricsAsync: ${toErrorStringWithHttpStatus(error)}`); 42 dispatch({ 43 type: GET_METRICS_ERROR, 44 error: toErrorString(error), 45 }); 46 } 47 }; 48 }