(ui): Add redux action/reducer for aggregating tasks

This commit is contained in:
Ken Hibino
2022-03-26 07:04:22 -07:00
parent f6d84b1dc2
commit a479098bd6
4 changed files with 148 additions and 1 deletions

View File

@@ -34,6 +34,7 @@ import {
listRetryTasks,
listScheduledTasks,
listCompletedTasks,
listAggregatingTasks,
PaginationOptions,
runAllArchivedTasks,
runAllRetryTasks,
@@ -75,6 +76,9 @@ export const LIST_ARCHIVED_TASKS_ERROR = "LIST_ARCHIVED_TASKS_ERROR";
export const LIST_COMPLETED_TASKS_BEGIN = "LIST_COMPLETED_TASKS_BEGIN";
export const LIST_COMPLETED_TASKS_SUCCESS = "LIST_COMPLETED_TASKS_SUCCESS";
export const LIST_COMPLETED_TASKS_ERROR = "LIST_COMPLETED_TASKS_ERROR";
export const LIST_AGGREGATING_TASKS_BEGIN = "LIST_AGGREGATING_TASKS_BEGIN";
export const LIST_AGGREGATING_TASKS_SUCCESS = "LIST_AGGREGATING_TASKS_SUCCESS";
export const LIST_AGGREGATING_TASKS_ERROR = "LIST_AGGREGATING_TASKS_ERROR";
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";
@@ -348,6 +352,26 @@ interface ListCompletedTasksErrorAction {
error: string; // error description
}
interface ListAggregatingTasksBeginAction {
type: typeof LIST_AGGREGATING_TASKS_BEGIN;
queue: string;
group: string;
}
interface ListAggregatingTasksSuccessAction {
type: typeof LIST_AGGREGATING_TASKS_SUCCESS;
queue: string;
group: string;
payload: ListTasksResponse;
}
interface ListAggregatingTasksErrorAction {
type: typeof LIST_AGGREGATING_TASKS_ERROR;
queue: string;
group: string;
error: string; // error description
}
interface CancelActiveTaskBeginAction {
type: typeof CANCEL_ACTIVE_TASK_BEGIN;
queue: string;
@@ -1024,6 +1048,9 @@ export type TasksActionTypes =
| ListCompletedTasksBeginAction
| ListCompletedTasksSuccessAction
| ListCompletedTasksErrorAction
| ListAggregatingTasksBeginAction
| ListAggregatingTasksSuccessAction
| ListAggregatingTasksErrorAction
| CancelActiveTaskBeginAction
| CancelActiveTaskSuccessAction
| CancelActiveTaskErrorAction
@@ -1314,6 +1341,40 @@ export function listCompletedTasksAsync(
};
}
export function listAggregatingTasksAsync(
qname: string,
gname: string,
pageOpts?: PaginationOptions
) {
return async (dispatch: Dispatch<TasksActionTypes>) => {
try {
dispatch({
type: LIST_AGGREGATING_TASKS_BEGIN,
queue: qname,
group: gname,
});
const response = await listAggregatingTasks(qname, gname, pageOpts);
dispatch({
type: LIST_AGGREGATING_TASKS_SUCCESS,
queue: qname,
group: gname,
payload: response,
});
} catch (error) {
console.error(
"listAggregatingTasksAsync: ",
toErrorStringWithHttpStatus(error)
);
dispatch({
type: LIST_AGGREGATING_TASKS_ERROR,
queue: qname,
group: gname,
error: toErrorString(error),
});
}
};
}
export function cancelActiveTaskAsync(queue: string, taskId: string) {
return async (dispatch: Dispatch<TasksActionTypes>) => {
dispatch({ type: CANCEL_ACTIVE_TASK_BEGIN, queue, taskId });