mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-08-24 14:48:42 +08:00
Initial commit
This commit is contained in:
158
ui/src/actions/queuesActions.ts
Normal file
158
ui/src/actions/queuesActions.ts
Normal file
@@ -0,0 +1,158 @@
|
||||
import {
|
||||
getQueue,
|
||||
GetQueueResponse,
|
||||
listQueues,
|
||||
ListQueuesResponse,
|
||||
pauseQueue,
|
||||
resumeQueue,
|
||||
} from "../api";
|
||||
import { Dispatch } from "redux";
|
||||
|
||||
// List of queue related action types.
|
||||
export const LIST_QUEUES_BEGIN = "LIST_QUEUES_BEGIN";
|
||||
export const LIST_QUEUES_SUCCESS = "LIST_QUEUES_SUCCESS";
|
||||
export const GET_QUEUE_BEGIN = "GET_QUEUE_BEGIN";
|
||||
export const GET_QUEUE_SUCCESS = "GET_QUEUE_SUCCESS";
|
||||
export const GET_QUEUE_ERROR = "GET_QUEUE_ERROR";
|
||||
export const PAUSE_QUEUE_BEGIN = "PAUSE_QUEUE_BEGIN";
|
||||
export const PAUSE_QUEUE_SUCCESS = "PAUSE_QUEUE_SUCCESS";
|
||||
export const PAUSE_QUEUE_ERROR = "PAUSE_QUEUE_ERROR";
|
||||
export const RESUME_QUEUE_BEGIN = "RESUME_QUEUE_BEGIN";
|
||||
export const RESUME_QUEUE_SUCCESS = "RESUME_QUEUE_SUCCESS";
|
||||
export const RESUME_QUEUE_ERROR = "RESUME_QUEUE_ERROR";
|
||||
|
||||
interface ListQueuesBeginAction {
|
||||
type: typeof LIST_QUEUES_BEGIN;
|
||||
}
|
||||
|
||||
interface ListQueuesSuccessAction {
|
||||
type: typeof LIST_QUEUES_SUCCESS;
|
||||
payload: ListQueuesResponse;
|
||||
}
|
||||
|
||||
interface GetQueueBeginAction {
|
||||
type: typeof GET_QUEUE_BEGIN;
|
||||
queue: string; // name of the queue
|
||||
}
|
||||
|
||||
interface GetQueueSuccessAction {
|
||||
type: typeof GET_QUEUE_SUCCESS;
|
||||
queue: string; // name of the queue
|
||||
payload: GetQueueResponse;
|
||||
}
|
||||
|
||||
interface GetQueueErrorAction {
|
||||
type: typeof GET_QUEUE_ERROR;
|
||||
queue: string; // name of the queue
|
||||
error: string; // error description
|
||||
}
|
||||
|
||||
interface PauseQueueBeginAction {
|
||||
type: typeof PAUSE_QUEUE_BEGIN;
|
||||
queue: string; // name of the queue
|
||||
}
|
||||
|
||||
interface PauseQueueSuccessAction {
|
||||
type: typeof PAUSE_QUEUE_SUCCESS;
|
||||
queue: string; // name of the queue
|
||||
}
|
||||
|
||||
interface PauseQueueErrorAction {
|
||||
type: typeof PAUSE_QUEUE_ERROR;
|
||||
queue: string; // name of the queue
|
||||
error: string; // error description
|
||||
}
|
||||
|
||||
interface ResumeQueueBeginAction {
|
||||
type: typeof RESUME_QUEUE_BEGIN;
|
||||
queue: string; // name of the queue
|
||||
}
|
||||
|
||||
interface ResumeQueueSuccessAction {
|
||||
type: typeof RESUME_QUEUE_SUCCESS;
|
||||
queue: string; // name of the queue
|
||||
}
|
||||
|
||||
interface ResumeQueueErrorAction {
|
||||
type: typeof RESUME_QUEUE_ERROR;
|
||||
queue: string; // name of the queue
|
||||
error: string; // error description
|
||||
}
|
||||
|
||||
// Union of all queues related action types.
|
||||
export type QueuesActionTypes =
|
||||
| ListQueuesBeginAction
|
||||
| ListQueuesSuccessAction
|
||||
| GetQueueBeginAction
|
||||
| GetQueueSuccessAction
|
||||
| GetQueueErrorAction
|
||||
| PauseQueueBeginAction
|
||||
| PauseQueueSuccessAction
|
||||
| PauseQueueErrorAction
|
||||
| ResumeQueueBeginAction
|
||||
| ResumeQueueSuccessAction
|
||||
| ResumeQueueErrorAction;
|
||||
|
||||
export function listQueuesAsync() {
|
||||
return async (dispatch: Dispatch<QueuesActionTypes>) => {
|
||||
dispatch({ type: LIST_QUEUES_BEGIN });
|
||||
// TODO: try/catch and dispatch error action on failure
|
||||
const response = await listQueues();
|
||||
dispatch({
|
||||
type: LIST_QUEUES_SUCCESS,
|
||||
payload: response,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function getQueueAsync(qname: string) {
|
||||
return async (dispatch: Dispatch<QueuesActionTypes>) => {
|
||||
dispatch({ type: GET_QUEUE_BEGIN, queue: qname });
|
||||
try {
|
||||
const response = await getQueue(qname);
|
||||
dispatch({
|
||||
type: GET_QUEUE_SUCCESS,
|
||||
queue: qname,
|
||||
payload: response,
|
||||
});
|
||||
} catch {
|
||||
dispatch({
|
||||
type: GET_QUEUE_ERROR,
|
||||
queue: qname,
|
||||
error: `Could not retrieve queue data for queue: ${qname}`,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function pauseQueueAsync(qname: string) {
|
||||
return async (dispatch: Dispatch<QueuesActionTypes>) => {
|
||||
dispatch({ type: PAUSE_QUEUE_BEGIN, queue: qname });
|
||||
try {
|
||||
await pauseQueue(qname);
|
||||
dispatch({ type: PAUSE_QUEUE_SUCCESS, queue: qname });
|
||||
} catch {
|
||||
dispatch({
|
||||
type: PAUSE_QUEUE_ERROR,
|
||||
queue: qname,
|
||||
error: `Could not pause queue: ${qname}`,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function resumeQueueAsync(qname: string) {
|
||||
return async (dispatch: Dispatch<QueuesActionTypes>) => {
|
||||
dispatch({ type: RESUME_QUEUE_BEGIN, queue: qname });
|
||||
try {
|
||||
await resumeQueue(qname);
|
||||
dispatch({ type: RESUME_QUEUE_SUCCESS, queue: qname });
|
||||
} catch {
|
||||
dispatch({
|
||||
type: RESUME_QUEUE_ERROR,
|
||||
queue: qname,
|
||||
error: `Could not resume queue: ${qname}`,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
17
ui/src/actions/settingsActions.ts
Normal file
17
ui/src/actions/settingsActions.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
// List of settings related action types.
|
||||
export const POLL_INTERVAL_CHANGE = "POLL_INTERVAL_CHANGE";
|
||||
|
||||
interface PollIntervalChangeAction {
|
||||
type: typeof POLL_INTERVAL_CHANGE;
|
||||
value: number; // new poll interval value in seconds
|
||||
}
|
||||
|
||||
// Union of all settings related action types.
|
||||
export type SettingsActionTypes = PollIntervalChangeAction;
|
||||
|
||||
export function pollIntervalChange(value: number) {
|
||||
return {
|
||||
type: POLL_INTERVAL_CHANGE,
|
||||
value,
|
||||
};
|
||||
}
|
246
ui/src/actions/tasksActions.ts
Normal file
246
ui/src/actions/tasksActions.ts
Normal file
@@ -0,0 +1,246 @@
|
||||
import {
|
||||
listActiveTasks,
|
||||
ListActiveTasksResponse,
|
||||
listDeadTasks,
|
||||
ListDeadTasksResponse,
|
||||
listPendingTasks,
|
||||
ListPendingTasksResponse,
|
||||
listRetryTasks,
|
||||
ListRetryTasksResponse,
|
||||
listScheduledTasks,
|
||||
ListScheduledTasksResponse,
|
||||
PaginationOptions,
|
||||
} from "../api";
|
||||
import { Dispatch } from "redux";
|
||||
|
||||
// List of tasks related action types.
|
||||
export const LIST_ACTIVE_TASKS_BEGIN = "LIST_ACTIVE_TASKS_BEGIN";
|
||||
export const LIST_ACTIVE_TASKS_SUCCESS = "LIST_ACTIVE_TASKS_SUCCESS";
|
||||
export const LIST_ACTIVE_TASKS_ERROR = "LIST_ACTIVE_TASKS_ERROR";
|
||||
export const LIST_PENDING_TASKS_BEGIN = "LIST_PENDING_TASKS_BEGIN";
|
||||
export const LIST_PENDING_TASKS_SUCCESS = "LIST_PENDING_TASKS_SUCCESS";
|
||||
export const LIST_PENDING_TASKS_ERROR = "LIST_PENDING_TASKS_ERROR";
|
||||
export const LIST_SCHEDULED_TASKS_BEGIN = "LIST_SCHEDULED_TASKS_BEGIN";
|
||||
export const LIST_SCHEDULED_TASKS_SUCCESS = "LIST_SCHEDULED_TASKS_SUCCESS";
|
||||
export const LIST_SCHEDULED_TASKS_ERROR = "LIST_SCHEDULED_TASKS_ERROR";
|
||||
export const LIST_RETRY_TASKS_BEGIN = "LIST_RETRY_TASKS_BEGIN";
|
||||
export const LIST_RETRY_TASKS_SUCCESS = "LIST_RETRY_TASKS_SUCCESS";
|
||||
export const LIST_RETRY_TASKS_ERROR = "LIST_RETRY_TASKS_ERROR";
|
||||
export const LIST_DEAD_TASKS_BEGIN = "LIST_DEAD_TASKS_BEGIN";
|
||||
export const LIST_DEAD_TASKS_SUCCESS = "LIST_DEAD_TASKS_SUCCESS";
|
||||
export const LIST_DEAD_TASKS_ERROR = "LIST_DEAD_TASKS_ERROR";
|
||||
|
||||
interface ListActiveTasksBeginAction {
|
||||
type: typeof LIST_ACTIVE_TASKS_BEGIN;
|
||||
queue: string;
|
||||
}
|
||||
|
||||
interface ListActiveTasksSuccessAction {
|
||||
type: typeof LIST_ACTIVE_TASKS_SUCCESS;
|
||||
queue: string;
|
||||
payload: ListActiveTasksResponse;
|
||||
}
|
||||
|
||||
interface ListActiveTasksErrorAction {
|
||||
type: typeof LIST_ACTIVE_TASKS_ERROR;
|
||||
queue: string;
|
||||
error: string; // error description
|
||||
}
|
||||
|
||||
interface ListPendingTasksBeginAction {
|
||||
type: typeof LIST_PENDING_TASKS_BEGIN;
|
||||
queue: string;
|
||||
}
|
||||
|
||||
interface ListPendingTasksSuccessAction {
|
||||
type: typeof LIST_PENDING_TASKS_SUCCESS;
|
||||
queue: string;
|
||||
payload: ListPendingTasksResponse;
|
||||
}
|
||||
|
||||
interface ListPendingTasksErrorAction {
|
||||
type: typeof LIST_PENDING_TASKS_ERROR;
|
||||
queue: string;
|
||||
error: string; // error description
|
||||
}
|
||||
|
||||
interface ListScheduledTasksBeginAction {
|
||||
type: typeof LIST_SCHEDULED_TASKS_BEGIN;
|
||||
queue: string;
|
||||
}
|
||||
|
||||
interface ListScheduledTasksSuccessAction {
|
||||
type: typeof LIST_SCHEDULED_TASKS_SUCCESS;
|
||||
queue: string;
|
||||
payload: ListScheduledTasksResponse;
|
||||
}
|
||||
|
||||
interface ListScheduledTasksErrorAction {
|
||||
type: typeof LIST_SCHEDULED_TASKS_ERROR;
|
||||
queue: string;
|
||||
error: string; // error description
|
||||
}
|
||||
|
||||
interface ListRetryTasksBeginAction {
|
||||
type: typeof LIST_RETRY_TASKS_BEGIN;
|
||||
queue: string;
|
||||
}
|
||||
|
||||
interface ListRetryTasksSuccessAction {
|
||||
type: typeof LIST_RETRY_TASKS_SUCCESS;
|
||||
queue: string;
|
||||
payload: ListRetryTasksResponse;
|
||||
}
|
||||
|
||||
interface ListRetryTasksErrorAction {
|
||||
type: typeof LIST_RETRY_TASKS_ERROR;
|
||||
queue: string;
|
||||
error: string; // error description
|
||||
}
|
||||
|
||||
interface ListDeadTasksBeginAction {
|
||||
type: typeof LIST_DEAD_TASKS_BEGIN;
|
||||
queue: string;
|
||||
}
|
||||
|
||||
interface ListDeadTasksSuccessAction {
|
||||
type: typeof LIST_DEAD_TASKS_SUCCESS;
|
||||
queue: string;
|
||||
payload: ListDeadTasksResponse;
|
||||
}
|
||||
|
||||
interface ListDeadTasksErrorAction {
|
||||
type: typeof LIST_DEAD_TASKS_ERROR;
|
||||
queue: string;
|
||||
error: string; // error description
|
||||
}
|
||||
|
||||
// Union of all tasks related action types.
|
||||
export type TasksActionTypes =
|
||||
| ListActiveTasksBeginAction
|
||||
| ListActiveTasksSuccessAction
|
||||
| ListActiveTasksErrorAction
|
||||
| ListPendingTasksBeginAction
|
||||
| ListPendingTasksSuccessAction
|
||||
| ListPendingTasksErrorAction
|
||||
| ListScheduledTasksBeginAction
|
||||
| ListScheduledTasksSuccessAction
|
||||
| ListScheduledTasksErrorAction
|
||||
| ListRetryTasksBeginAction
|
||||
| ListRetryTasksSuccessAction
|
||||
| ListRetryTasksErrorAction
|
||||
| ListDeadTasksBeginAction
|
||||
| ListDeadTasksSuccessAction
|
||||
| ListDeadTasksErrorAction;
|
||||
|
||||
export function listActiveTasksAsync(qname: string) {
|
||||
return async (dispatch: Dispatch<TasksActionTypes>) => {
|
||||
dispatch({ type: LIST_ACTIVE_TASKS_BEGIN, queue: qname });
|
||||
try {
|
||||
const response = await listActiveTasks(qname);
|
||||
dispatch({
|
||||
type: LIST_ACTIVE_TASKS_SUCCESS,
|
||||
queue: qname,
|
||||
payload: response,
|
||||
});
|
||||
} catch {
|
||||
dispatch({
|
||||
type: LIST_ACTIVE_TASKS_ERROR,
|
||||
queue: qname,
|
||||
error: `Could not retreive active tasks data for queue: ${qname}`,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function listPendingTasksAsync(
|
||||
qname: string,
|
||||
pageOpts?: PaginationOptions
|
||||
) {
|
||||
return async (dispatch: Dispatch<TasksActionTypes>) => {
|
||||
dispatch({ type: LIST_PENDING_TASKS_BEGIN, queue: qname });
|
||||
try {
|
||||
const response = await listPendingTasks(qname, pageOpts);
|
||||
dispatch({
|
||||
type: LIST_PENDING_TASKS_SUCCESS,
|
||||
queue: qname,
|
||||
payload: response,
|
||||
});
|
||||
} catch {
|
||||
dispatch({
|
||||
type: LIST_PENDING_TASKS_ERROR,
|
||||
queue: qname,
|
||||
error: `Could not retreive pending tasks data for queue: ${qname}`,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function listScheduledTasksAsync(
|
||||
qname: string,
|
||||
pageOpts?: PaginationOptions
|
||||
) {
|
||||
return async (dispatch: Dispatch<TasksActionTypes>) => {
|
||||
dispatch({ type: LIST_SCHEDULED_TASKS_BEGIN, queue: qname });
|
||||
try {
|
||||
const response = await listScheduledTasks(qname, pageOpts);
|
||||
dispatch({
|
||||
type: LIST_SCHEDULED_TASKS_SUCCESS,
|
||||
queue: qname,
|
||||
payload: response,
|
||||
});
|
||||
} catch {
|
||||
dispatch({
|
||||
type: LIST_SCHEDULED_TASKS_ERROR,
|
||||
queue: qname,
|
||||
error: `Could not retreive scheduled tasks data for queue: ${qname}`,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function listRetryTasksAsync(
|
||||
qname: string,
|
||||
pageOpts?: PaginationOptions
|
||||
) {
|
||||
return async (dispatch: Dispatch<TasksActionTypes>) => {
|
||||
dispatch({ type: LIST_RETRY_TASKS_BEGIN, queue: qname });
|
||||
try {
|
||||
const response = await listRetryTasks(qname, pageOpts);
|
||||
dispatch({
|
||||
type: LIST_RETRY_TASKS_SUCCESS,
|
||||
queue: qname,
|
||||
payload: response,
|
||||
});
|
||||
} catch {
|
||||
dispatch({
|
||||
type: LIST_RETRY_TASKS_ERROR,
|
||||
queue: qname,
|
||||
error: `Could not retreive retry tasks data for queue: ${qname}`,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function listDeadTasksAsync(
|
||||
qname: string,
|
||||
pageOpts?: PaginationOptions
|
||||
) {
|
||||
return async (dispatch: Dispatch<TasksActionTypes>) => {
|
||||
dispatch({ type: LIST_DEAD_TASKS_BEGIN, queue: qname });
|
||||
try {
|
||||
const response = await listDeadTasks(qname, pageOpts);
|
||||
dispatch({
|
||||
type: LIST_DEAD_TASKS_SUCCESS,
|
||||
queue: qname,
|
||||
payload: response,
|
||||
});
|
||||
} catch {
|
||||
dispatch({
|
||||
type: LIST_DEAD_TASKS_ERROR,
|
||||
queue: qname,
|
||||
error: `Could not retreive dead tasks data for queue: ${qname}`,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user