diff --git a/ui/src/actions/tasksActions.ts b/ui/src/actions/tasksActions.ts index d5ad55b..6e01125 100644 --- a/ui/src/actions/tasksActions.ts +++ b/ui/src/actions/tasksActions.ts @@ -47,11 +47,16 @@ import { archivePendingTask, batchArchivePendingTasks, archiveAllPendingTasks, + TaskInfo, + getTaskInfo, } from "../api"; import { Dispatch } from "redux"; import { toErrorString, toErrorStringWithHttpStatus } from "../utils"; // List of tasks related action types. +export const GET_TASK_INFO_BEGIN = "GET_TASK_INFO_BEGIN"; +export const GET_TASK_INFO_SUCCESS = "GET_TASK_INFO_SUCCESS"; +export const GET_TASK_INFO_ERROR = "GET_TASK_INFO_ERROR"; 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"; @@ -209,6 +214,20 @@ export const DELETE_ALL_ARCHIVED_TASKS_SUCCESS = export const DELETE_ALL_ARCHIVED_TASKS_ERROR = "DELETE_ALL_ARCHIVED_TASKS_ERROR"; +interface GetTaskInfoBeginAction { + type: typeof GET_TASK_INFO_BEGIN; +} + +interface GetTaskInfoErrorAction { + type: typeof GET_TASK_INFO_ERROR; + error: string; // error description +} + +interface GetTaskInfoSuccessAction { + type: typeof GET_TASK_INFO_SUCCESS; + payload: TaskInfo; +} + interface ListActiveTasksBeginAction { type: typeof LIST_ACTIVE_TASKS_BEGIN; queue: string; @@ -894,6 +913,9 @@ interface DeleteAllArchivedTasksErrorAction { // Union of all tasks related action types. export type TasksActionTypes = + | GetTaskInfoBeginAction + | GetTaskInfoErrorAction + | GetTaskInfoSuccessAction | ListActiveTasksBeginAction | ListActiveTasksSuccessAction | ListActiveTasksErrorAction @@ -1009,6 +1031,25 @@ export type TasksActionTypes = | DeleteAllArchivedTasksSuccessAction | DeleteAllArchivedTasksErrorAction; +export function getTaskInfoAsync(qname: string, id: string) { + return async (dispatch: Dispatch) => { + dispatch({ type: GET_TASK_INFO_BEGIN }); + try { + const response = await getTaskInfo(qname, id); + dispatch({ + type: GET_TASK_INFO_SUCCESS, + payload: response, + }) + } catch (error) { + console.error("getTaskInfoAsync: ", toErrorStringWithHttpStatus(error)); + dispatch({ + type: GET_TASK_INFO_ERROR, + error: toErrorString(error), + }) + } + } +} + export function listActiveTasksAsync( qname: string, pageOpts?: PaginationOptions diff --git a/ui/src/api.ts b/ui/src/api.ts index 574dbcb..dfdd975 100644 --- a/ui/src/api.ts +++ b/ui/src/api.ts @@ -245,6 +245,19 @@ interface BaseTask { payload: string; } +export interface TaskInfo { + id: string; + queue: string; + type: string; + max_retry: number; + retried: number; + last_failed_at: string; + error_message: string; + next_process_at: string; + timeout_seconds: number; + deadline: string; +} + export interface ActiveTask extends BaseTask { id: string; queue: string; @@ -369,6 +382,15 @@ export async function listQueueStats(): Promise { return resp.data; } +export async function getTaskInfo(qname: string, id: string): Promise { + const url = `${BASE_URL}/queues/${qname}/tasks/${id}`; + const resp = await axios({ + method: "get", + url, + }); + return resp.data; +} + export async function listActiveTasks( qname: string, pageOpts?: PaginationOptions diff --git a/ui/src/reducers/tasksReducer.ts b/ui/src/reducers/tasksReducer.ts index 1a4454e..7ddb758 100644 --- a/ui/src/reducers/tasksReducer.ts +++ b/ui/src/reducers/tasksReducer.ts @@ -114,6 +114,9 @@ import { BATCH_DELETE_PENDING_TASKS_SUCCESS, BATCH_ARCHIVE_PENDING_TASKS_ERROR, BATCH_DELETE_PENDING_TASKS_ERROR, + GET_TASK_INFO_BEGIN, + GET_TASK_INFO_ERROR, + GET_TASK_INFO_SUCCESS, } from "../actions/tasksActions"; import { ActiveTask, @@ -121,6 +124,7 @@ import { PendingTask, RetryTask, ScheduledTask, + TaskInfo, } from "../api"; export interface ActiveTaskExtended extends ActiveTask { @@ -193,6 +197,11 @@ interface TasksState { error: string; data: ArchivedTaskExtended[]; }; + taskInfo: { + loading: boolean; + error: string; + data?: TaskInfo; + }, } const initialState: TasksState = { @@ -231,6 +240,10 @@ const initialState: TasksState = { error: "", data: [], }, + taskInfo: { + loading: false, + error: "", + } }; function tasksReducer( @@ -238,6 +251,34 @@ function tasksReducer( action: TasksActionTypes ): TasksState { switch (action.type) { + case GET_TASK_INFO_BEGIN: + return { + ...state, + taskInfo: { + loading: true, + error: "", + }, + } + + case GET_TASK_INFO_ERROR: + return { + ...state, + taskInfo: { + loading: false, + error: action.error, + }, + }; + + case GET_TASK_INFO_SUCCESS: + return { + ...state, + taskInfo: { + loading: false, + error: "", + data: action.payload, + }, + }; + case LIST_ACTIVE_TASKS_BEGIN: return { ...state,