2
0
mirror of https://github.com/hibiken/asynqmon.git synced 2025-10-26 08:16:10 +08:00
Files
asynqmon/ui/src/actions/redisInfoActions.ts
2021-01-09 14:17:44 -08:00

45 lines
1.3 KiB
TypeScript

import { Dispatch } from "redux";
import { getRedisInfo, RedisInfoResponse } from "../api";
import { toErrorString } from "../utils";
// List of redis-info related action types.
export const GET_REDIS_INFO_BEGIN = "GET_REDIS_INFO_BEGIN";
export const GET_REDIS_INFO_SUCCESS = "GET_REDIS_INFO_SUCCESS";
export const GET_REDIS_INFO_ERROR = "GET_REDIS_INFO_ERROR";
interface GetRedisInfoBeginAction {
type: typeof GET_REDIS_INFO_BEGIN;
}
interface GetRedisInfoSuccessAction {
type: typeof GET_REDIS_INFO_SUCCESS;
payload: RedisInfoResponse;
}
interface GetRedisInfoErrorAction {
type: typeof GET_REDIS_INFO_ERROR;
error: string;
}
// Union of all redis-info related actions.
export type RedisInfoActionTypes =
| GetRedisInfoBeginAction
| GetRedisInfoErrorAction
| GetRedisInfoSuccessAction;
export function getRedisInfoAsync() {
return async (dispatch: Dispatch<RedisInfoActionTypes>) => {
dispatch({ type: GET_REDIS_INFO_BEGIN });
try {
const response = await getRedisInfo();
dispatch({ type: GET_REDIS_INFO_SUCCESS, payload: response });
} catch (error) {
console.error(`getRedisInfoAsync: ${toErrorString(error)}`);
dispatch({
type: GET_REDIS_INFO_ERROR,
error: error.response.data,
});
}
};
}