2020-11-24 22:54:00 +08:00
|
|
|
import {
|
2020-12-06 01:24:42 +08:00
|
|
|
cancelActiveTask,
|
2020-11-24 22:54:00 +08:00
|
|
|
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";
|
2020-12-06 01:24:42 +08:00
|
|
|
export const CANCEL_ACTIVE_TASK_BEGIN = "CANCEL_ACTIVE_TASK_BEGIN";
|
|
|
|
export const CANCEL_ACTIVE_TASK_SUCCESS = "CANCEL_ACTIVE_TASK_SUCCESS";
|
|
|
|
export const CANCEL_ACTIVE_TASK_ERROR = "CANCEL_ACTIVE_TASK_ERROR";
|
2020-11-24 22:54:00 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-12-06 01:24:42 +08:00
|
|
|
interface CancelActiveTaskBeginAction {
|
|
|
|
type: typeof CANCEL_ACTIVE_TASK_BEGIN;
|
|
|
|
queue: string;
|
|
|
|
taskId: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface CancelActiveTaskSuccessAction {
|
|
|
|
type: typeof CANCEL_ACTIVE_TASK_SUCCESS;
|
|
|
|
queue: string;
|
|
|
|
taskId: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface CancelActiveTaskErrorAction {
|
|
|
|
type: typeof CANCEL_ACTIVE_TASK_ERROR;
|
|
|
|
queue: string;
|
|
|
|
taskId: string;
|
|
|
|
error: string;
|
|
|
|
}
|
|
|
|
|
2020-11-24 22:54:00 +08:00
|
|
|
// Union of all tasks related action types.
|
|
|
|
export type TasksActionTypes =
|
|
|
|
| ListActiveTasksBeginAction
|
|
|
|
| ListActiveTasksSuccessAction
|
|
|
|
| ListActiveTasksErrorAction
|
|
|
|
| ListPendingTasksBeginAction
|
|
|
|
| ListPendingTasksSuccessAction
|
|
|
|
| ListPendingTasksErrorAction
|
|
|
|
| ListScheduledTasksBeginAction
|
|
|
|
| ListScheduledTasksSuccessAction
|
|
|
|
| ListScheduledTasksErrorAction
|
|
|
|
| ListRetryTasksBeginAction
|
|
|
|
| ListRetryTasksSuccessAction
|
|
|
|
| ListRetryTasksErrorAction
|
|
|
|
| ListDeadTasksBeginAction
|
|
|
|
| ListDeadTasksSuccessAction
|
2020-12-06 01:24:42 +08:00
|
|
|
| ListDeadTasksErrorAction
|
|
|
|
| CancelActiveTaskBeginAction
|
|
|
|
| CancelActiveTaskSuccessAction
|
|
|
|
| CancelActiveTaskErrorAction;
|
2020-11-24 22:54:00 +08:00
|
|
|
|
2020-11-30 07:04:24 +08:00
|
|
|
export function listActiveTasksAsync(
|
|
|
|
qname: string,
|
|
|
|
pageOpts?: PaginationOptions
|
|
|
|
) {
|
2020-11-24 22:54:00 +08:00
|
|
|
return async (dispatch: Dispatch<TasksActionTypes>) => {
|
|
|
|
dispatch({ type: LIST_ACTIVE_TASKS_BEGIN, queue: qname });
|
|
|
|
try {
|
2020-11-30 07:04:24 +08:00
|
|
|
const response = await listActiveTasks(qname, pageOpts);
|
2020-11-24 22:54:00 +08:00
|
|
|
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}`,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2020-12-06 01:24:42 +08:00
|
|
|
|
|
|
|
export function cancelActiveTaskAsync(queue: string, taskId: string) {
|
|
|
|
return async (dispatch: Dispatch<TasksActionTypes>) => {
|
|
|
|
dispatch({ type: CANCEL_ACTIVE_TASK_BEGIN, queue, taskId });
|
|
|
|
try {
|
|
|
|
await cancelActiveTask(queue, taskId);
|
|
|
|
dispatch({ type: CANCEL_ACTIVE_TASK_SUCCESS, queue, taskId });
|
|
|
|
} catch {
|
|
|
|
dispatch({
|
|
|
|
type: CANCEL_ACTIVE_TASK_ERROR,
|
|
|
|
error: `Could not cancel task: ${taskId}`,
|
|
|
|
queue,
|
|
|
|
taskId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|