mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-01-19 03:05:53 +08:00
Add redux actions and reducer for scheduler entries
This commit is contained in:
parent
fbbc414bdf
commit
3e5b145883
46
ui/src/actions/schedulerEntriesActions.ts
Normal file
46
ui/src/actions/schedulerEntriesActions.ts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import { Dispatch } from "@reduxjs/toolkit";
|
||||||
|
import { listSchedulerEntries, ListSchedulerEntriesResponse } from "../api";
|
||||||
|
|
||||||
|
// List of scheduler-entry related action types.
|
||||||
|
export const LIST_SCHEDULER_ENTRIES_BEGIN = "LIST_SCHEDULER_ENTRIES_BEGIN";
|
||||||
|
export const LIST_SCHEDULER_ENTRIES_SUCCESS = "LIST_SCHEDULER_ENTRIES_SUCCESS";
|
||||||
|
export const LIST_SCHEDULER_ENTRIES_ERROR = "LIST_SCHEDULER_ENTRIES_ERROR";
|
||||||
|
|
||||||
|
interface ListSchedulerEntriesBeginAction {
|
||||||
|
type: typeof LIST_SCHEDULER_ENTRIES_BEGIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ListSchedulerEntriesSuccessAction {
|
||||||
|
type: typeof LIST_SCHEDULER_ENTRIES_SUCCESS;
|
||||||
|
payload: ListSchedulerEntriesResponse;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ListSchedulerEntriesErrorAction {
|
||||||
|
type: typeof LIST_SCHEDULER_ENTRIES_ERROR;
|
||||||
|
error: string; // error description
|
||||||
|
}
|
||||||
|
|
||||||
|
// Union of all scheduler-entry related actions.
|
||||||
|
export type SchedulerEntriesActionTypes =
|
||||||
|
| ListSchedulerEntriesBeginAction
|
||||||
|
| ListSchedulerEntriesSuccessAction
|
||||||
|
| ListSchedulerEntriesErrorAction;
|
||||||
|
|
||||||
|
export function listSchedulerEntriesAsync() {
|
||||||
|
return async (dispatch: Dispatch<SchedulerEntriesActionTypes>) => {
|
||||||
|
dispatch({ type: LIST_SCHEDULER_ENTRIES_BEGIN });
|
||||||
|
try {
|
||||||
|
const response = await listSchedulerEntries();
|
||||||
|
dispatch({
|
||||||
|
type: LIST_SCHEDULER_ENTRIES_SUCCESS,
|
||||||
|
payload: response,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
dispatch({
|
||||||
|
type: LIST_SCHEDULER_ENTRIES_ERROR,
|
||||||
|
error: "Could not retrieve scheduler entries",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@ -37,6 +37,10 @@ export interface ListDeadTasksResponse {
|
|||||||
stats: Queue;
|
stats: Queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ListSchedulerEntriesResponse {
|
||||||
|
entries: SchedulerEntry[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface Queue {
|
export interface Queue {
|
||||||
queue: string;
|
queue: string;
|
||||||
paused: boolean;
|
paused: boolean;
|
||||||
@ -97,6 +101,16 @@ export interface DeadTask extends BaseTask {
|
|||||||
error_message: string;
|
error_message: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SchedulerEntry {
|
||||||
|
id: string;
|
||||||
|
spec: string;
|
||||||
|
task_type: string;
|
||||||
|
task_payload: { [key: string]: any };
|
||||||
|
options: string[];
|
||||||
|
next_enqueue_at: string;
|
||||||
|
prev_enqueue_at: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface PaginationOptions extends Record<string, number | undefined> {
|
export interface PaginationOptions extends Record<string, number | undefined> {
|
||||||
size?: number; // size of the page
|
size?: number; // size of the page
|
||||||
page?: number; // page number (1 being the first page)
|
page?: number; // page number (1 being the first page)
|
||||||
@ -213,3 +227,11 @@ export async function listDeadTasks(
|
|||||||
});
|
});
|
||||||
return resp.data;
|
return resp.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function listSchedulerEntries(): Promise<ListSchedulerEntriesResponse> {
|
||||||
|
const resp = await axios({
|
||||||
|
method: "get",
|
||||||
|
url: `${BASE_URL}/scheduler_entries`,
|
||||||
|
});
|
||||||
|
return resp.data;
|
||||||
|
}
|
||||||
|
49
ui/src/reducers/schedulerEntriesReducer.ts
Normal file
49
ui/src/reducers/schedulerEntriesReducer.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import {
|
||||||
|
LIST_SCHEDULER_ENTRIES_BEGIN,
|
||||||
|
LIST_SCHEDULER_ENTRIES_ERROR,
|
||||||
|
LIST_SCHEDULER_ENTRIES_SUCCESS,
|
||||||
|
SchedulerEntriesActionTypes,
|
||||||
|
} from "../actions/schedulerEntriesActions";
|
||||||
|
import { SchedulerEntry } from "../api";
|
||||||
|
|
||||||
|
interface SchedulerEntriesState {
|
||||||
|
loading: boolean;
|
||||||
|
data: SchedulerEntry[];
|
||||||
|
error: string; // error description
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialState: SchedulerEntriesState = {
|
||||||
|
loading: false,
|
||||||
|
data: [],
|
||||||
|
error: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
function schedulerEntriesReducer(
|
||||||
|
state = initialState,
|
||||||
|
action: SchedulerEntriesActionTypes
|
||||||
|
): SchedulerEntriesState {
|
||||||
|
switch (action.type) {
|
||||||
|
case LIST_SCHEDULER_ENTRIES_BEGIN:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
loading: true,
|
||||||
|
};
|
||||||
|
case LIST_SCHEDULER_ENTRIES_SUCCESS:
|
||||||
|
return {
|
||||||
|
error: "",
|
||||||
|
loading: false,
|
||||||
|
data: action.payload.entries,
|
||||||
|
};
|
||||||
|
case LIST_SCHEDULER_ENTRIES_ERROR:
|
||||||
|
// TODO: set error state
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
loading: false,
|
||||||
|
error: action.error,
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default schedulerEntriesReducer;
|
@ -2,11 +2,13 @@ import { combineReducers, configureStore } from "@reduxjs/toolkit";
|
|||||||
import settingsReducer from "./reducers/settingsReducer";
|
import settingsReducer from "./reducers/settingsReducer";
|
||||||
import queuesReducer from "./reducers/queuesReducer";
|
import queuesReducer from "./reducers/queuesReducer";
|
||||||
import tasksReducer from "./reducers/tasksReducer";
|
import tasksReducer from "./reducers/tasksReducer";
|
||||||
|
import schedulerEntriesReducer from "./reducers/schedulerEntriesReducer";
|
||||||
|
|
||||||
const rootReducer = combineReducers({
|
const rootReducer = combineReducers({
|
||||||
settings: settingsReducer,
|
settings: settingsReducer,
|
||||||
queues: queuesReducer,
|
queues: queuesReducer,
|
||||||
tasks: tasksReducer,
|
tasks: tasksReducer,
|
||||||
|
schedulerEntries: schedulerEntriesReducer,
|
||||||
});
|
});
|
||||||
|
|
||||||
// AppState is the top-level application state maintained by redux store.
|
// AppState is the top-level application state maintained by redux store.
|
Loading…
Reference in New Issue
Block a user