mirror of
https://github.com/hibiken/asynqmon.git
synced 2026-07-31 16:32:22 +08:00
Initial commit
This commit is contained in:
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