github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/asynqmon/ui/src/actions/redisInfoActions.ts (about)

     1  import { Dispatch } from "redux";
     2  import { getRedisInfo, RedisInfoResponse } from "../api";
     3  import { toErrorString, toErrorStringWithHttpStatus } from "../utils";
     4  
     5  // List of redis-info related action types.
     6  export const GET_REDIS_INFO_BEGIN = "GET_REDIS_INFO_BEGIN";
     7  export const GET_REDIS_INFO_SUCCESS = "GET_REDIS_INFO_SUCCESS";
     8  export const GET_REDIS_INFO_ERROR = "GET_REDIS_INFO_ERROR";
     9  
    10  interface GetRedisInfoBeginAction {
    11    type: typeof GET_REDIS_INFO_BEGIN;
    12  }
    13  
    14  interface GetRedisInfoSuccessAction {
    15    type: typeof GET_REDIS_INFO_SUCCESS;
    16    payload: RedisInfoResponse;
    17  }
    18  
    19  interface GetRedisInfoErrorAction {
    20    type: typeof GET_REDIS_INFO_ERROR;
    21    error: string;
    22  }
    23  
    24  // Union of all redis-info related actions.
    25  export type RedisInfoActionTypes =
    26    | GetRedisInfoBeginAction
    27    | GetRedisInfoErrorAction
    28    | GetRedisInfoSuccessAction;
    29  
    30  export function getRedisInfoAsync() {
    31    return async (dispatch: Dispatch<RedisInfoActionTypes>) => {
    32      dispatch({ type: GET_REDIS_INFO_BEGIN });
    33      try {
    34        const response = await getRedisInfo();
    35        dispatch({ type: GET_REDIS_INFO_SUCCESS, payload: response });
    36      } catch (error) {
    37        console.error(`getRedisInfoAsync: ${toErrorStringWithHttpStatus(error)}`);
    38        dispatch({
    39          type: GET_REDIS_INFO_ERROR,
    40          error: toErrorString(error),
    41        });
    42      }
    43    };
    44  }