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

     1  import { Dispatch } from "redux";
     2  import { listQueueStats, ListQueueStatsResponse } from "../api";
     3  import { toErrorString, toErrorStringWithHttpStatus } from "../utils";
     4  
     5  export const LIST_QUEUE_STATS_BEGIN = "LIST_QUEUE_STATS_BEGIN";
     6  export const LIST_QUEUE_STATS_SUCCESS = "LIST_QUEUE_STATS_SUCCESS";
     7  export const LIST_QUEUE_STATS_ERROR = "LIST_QUEUE_STATS_ERROR";
     8  
     9  interface ListQueueStatsBeginAction {
    10    type: typeof LIST_QUEUE_STATS_BEGIN;
    11  }
    12  
    13  interface ListQueueStatsSuccessAction {
    14    type: typeof LIST_QUEUE_STATS_SUCCESS;
    15    payload: ListQueueStatsResponse;
    16  }
    17  
    18  interface ListQueueStatsErrorAction {
    19    type: typeof LIST_QUEUE_STATS_ERROR;
    20    error: string;
    21  }
    22  
    23  // Union of all queue stats related action types.
    24  export type QueueStatsActionTypes =
    25    | ListQueueStatsBeginAction
    26    | ListQueueStatsSuccessAction
    27    | ListQueueStatsErrorAction;
    28  
    29  export function listQueueStatsAsync() {
    30    return async (dispatch: Dispatch<QueueStatsActionTypes>) => {
    31      dispatch({ type: LIST_QUEUE_STATS_BEGIN });
    32      try {
    33        const response = await listQueueStats();
    34        dispatch({
    35          type: LIST_QUEUE_STATS_SUCCESS,
    36          payload: response,
    37        });
    38      } catch (error) {
    39        console.error(
    40          "listQueueStatsAsync: ",
    41          toErrorStringWithHttpStatus(error)
    42        );
    43        dispatch({
    44          type: LIST_QUEUE_STATS_ERROR,
    45          error: toErrorString(error),
    46        });
    47      }
    48    };
    49  }