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

     1  import { Dispatch } from "@reduxjs/toolkit";
     2  import {
     3    listSchedulerEnqueueEvents,
     4    ListSchedulerEnqueueEventsResponse,
     5    listSchedulerEntries,
     6    ListSchedulerEntriesResponse,
     7  } from "../api";
     8  import { toErrorString, toErrorStringWithHttpStatus } from "../utils";
     9  
    10  // List of scheduler-entry related action types.
    11  export const LIST_SCHEDULER_ENTRIES_BEGIN = "LIST_SCHEDULER_ENTRIES_BEGIN";
    12  export const LIST_SCHEDULER_ENTRIES_SUCCESS = "LIST_SCHEDULER_ENTRIES_SUCCESS";
    13  export const LIST_SCHEDULER_ENTRIES_ERROR = "LIST_SCHEDULER_ENTRIES_ERROR";
    14  export const LIST_SCHEDULER_ENQUEUE_EVENTS_BEGIN =
    15    "LIST_SCHEDULER_ENQUEUE_EVENTS_BEGIN";
    16  export const LIST_SCHEDULER_ENQUEUE_EVENTS_SUCCESS =
    17    "LIST_SCHEDULER_ENQUEUE_EVENTS_SUCCESS";
    18  export const LIST_SCHEDULER_ENQUEUE_EVENTS_ERROR =
    19    "LIST_SCHEDULER_ENQUEUE_EVENTS_ERROR";
    20  
    21  interface ListSchedulerEntriesBeginAction {
    22    type: typeof LIST_SCHEDULER_ENTRIES_BEGIN;
    23  }
    24  
    25  interface ListSchedulerEntriesSuccessAction {
    26    type: typeof LIST_SCHEDULER_ENTRIES_SUCCESS;
    27    payload: ListSchedulerEntriesResponse;
    28  }
    29  
    30  interface ListSchedulerEntriesErrorAction {
    31    type: typeof LIST_SCHEDULER_ENTRIES_ERROR;
    32    error: string; // error description
    33  }
    34  
    35  interface ListSchedulerEnqueueEventBeginAction {
    36    type: typeof LIST_SCHEDULER_ENQUEUE_EVENTS_BEGIN;
    37    entryId: string;
    38  }
    39  
    40  interface ListSchedulerEnqueueEventSuccessAction {
    41    type: typeof LIST_SCHEDULER_ENQUEUE_EVENTS_SUCCESS;
    42    entryId: string;
    43    payload: ListSchedulerEnqueueEventsResponse;
    44  }
    45  
    46  interface ListSchedulerEnqueueEventErrorAction {
    47    type: typeof LIST_SCHEDULER_ENQUEUE_EVENTS_ERROR;
    48    entryId: string;
    49    error: string;
    50  }
    51  
    52  // Union of all scheduler-entry related actions.
    53  export type SchedulerEntriesActionTypes =
    54    | ListSchedulerEntriesBeginAction
    55    | ListSchedulerEntriesSuccessAction
    56    | ListSchedulerEntriesErrorAction
    57    | ListSchedulerEnqueueEventBeginAction
    58    | ListSchedulerEnqueueEventSuccessAction
    59    | ListSchedulerEnqueueEventErrorAction;
    60  
    61  export function listSchedulerEntriesAsync() {
    62    return async (dispatch: Dispatch<SchedulerEntriesActionTypes>) => {
    63      dispatch({ type: LIST_SCHEDULER_ENTRIES_BEGIN });
    64      try {
    65        const response = await listSchedulerEntries();
    66        dispatch({
    67          type: LIST_SCHEDULER_ENTRIES_SUCCESS,
    68          payload: response,
    69        });
    70      } catch (error) {
    71        console.error(
    72          `listSchedulerEnqueueEventsAsync: ${toErrorStringWithHttpStatus(error)}`
    73        );
    74        dispatch({
    75          type: LIST_SCHEDULER_ENTRIES_ERROR,
    76          error: toErrorString(error),
    77        });
    78      }
    79    };
    80  }
    81  
    82  export function listSchedulerEnqueueEventsAsync(entryId: string) {
    83    return async (dispatch: Dispatch<SchedulerEntriesActionTypes>) => {
    84      dispatch({ type: LIST_SCHEDULER_ENQUEUE_EVENTS_BEGIN, entryId });
    85      try {
    86        const response = await listSchedulerEnqueueEvents(entryId);
    87        dispatch({
    88          type: LIST_SCHEDULER_ENQUEUE_EVENTS_SUCCESS,
    89          payload: response,
    90          entryId,
    91        });
    92      } catch (error) {
    93        console.error(
    94          "listSchedulerEnqueueEventsAsync: ",
    95          toErrorStringWithHttpStatus(error)
    96        );
    97        dispatch({
    98          type: LIST_SCHEDULER_ENQUEUE_EVENTS_ERROR,
    99          error: toErrorString(error),
   100          entryId,
   101        });
   102      }
   103    };
   104  }