mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-10-26 00:06:13 +08:00
Add reducer and actions related to GetTaskInfo
This commit is contained in:
@@ -47,11 +47,16 @@ import {
|
|||||||
archivePendingTask,
|
archivePendingTask,
|
||||||
batchArchivePendingTasks,
|
batchArchivePendingTasks,
|
||||||
archiveAllPendingTasks,
|
archiveAllPendingTasks,
|
||||||
|
TaskInfo,
|
||||||
|
getTaskInfo,
|
||||||
} from "../api";
|
} from "../api";
|
||||||
import { Dispatch } from "redux";
|
import { Dispatch } from "redux";
|
||||||
import { toErrorString, toErrorStringWithHttpStatus } from "../utils";
|
import { toErrorString, toErrorStringWithHttpStatus } from "../utils";
|
||||||
|
|
||||||
// List of tasks related action types.
|
// 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_BEGIN = "LIST_ACTIVE_TASKS_BEGIN";
|
||||||
export const LIST_ACTIVE_TASKS_SUCCESS = "LIST_ACTIVE_TASKS_SUCCESS";
|
export const LIST_ACTIVE_TASKS_SUCCESS = "LIST_ACTIVE_TASKS_SUCCESS";
|
||||||
export const LIST_ACTIVE_TASKS_ERROR = "LIST_ACTIVE_TASKS_ERROR";
|
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 =
|
export const DELETE_ALL_ARCHIVED_TASKS_ERROR =
|
||||||
"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 {
|
interface ListActiveTasksBeginAction {
|
||||||
type: typeof LIST_ACTIVE_TASKS_BEGIN;
|
type: typeof LIST_ACTIVE_TASKS_BEGIN;
|
||||||
queue: string;
|
queue: string;
|
||||||
@@ -894,6 +913,9 @@ interface DeleteAllArchivedTasksErrorAction {
|
|||||||
|
|
||||||
// Union of all tasks related action types.
|
// Union of all tasks related action types.
|
||||||
export type TasksActionTypes =
|
export type TasksActionTypes =
|
||||||
|
| GetTaskInfoBeginAction
|
||||||
|
| GetTaskInfoErrorAction
|
||||||
|
| GetTaskInfoSuccessAction
|
||||||
| ListActiveTasksBeginAction
|
| ListActiveTasksBeginAction
|
||||||
| ListActiveTasksSuccessAction
|
| ListActiveTasksSuccessAction
|
||||||
| ListActiveTasksErrorAction
|
| ListActiveTasksErrorAction
|
||||||
@@ -1009,6 +1031,25 @@ export type TasksActionTypes =
|
|||||||
| DeleteAllArchivedTasksSuccessAction
|
| DeleteAllArchivedTasksSuccessAction
|
||||||
| DeleteAllArchivedTasksErrorAction;
|
| DeleteAllArchivedTasksErrorAction;
|
||||||
|
|
||||||
|
export function getTaskInfoAsync(qname: string, id: string) {
|
||||||
|
return async (dispatch: Dispatch<TasksActionTypes>) => {
|
||||||
|
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(
|
export function listActiveTasksAsync(
|
||||||
qname: string,
|
qname: string,
|
||||||
pageOpts?: PaginationOptions
|
pageOpts?: PaginationOptions
|
||||||
|
|||||||
@@ -245,6 +245,19 @@ interface BaseTask {
|
|||||||
payload: string;
|
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 {
|
export interface ActiveTask extends BaseTask {
|
||||||
id: string;
|
id: string;
|
||||||
queue: string;
|
queue: string;
|
||||||
@@ -369,6 +382,15 @@ export async function listQueueStats(): Promise<ListQueueStatsResponse> {
|
|||||||
return resp.data;
|
return resp.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getTaskInfo(qname: string, id: string): Promise<TaskInfo> {
|
||||||
|
const url = `${BASE_URL}/queues/${qname}/tasks/${id}`;
|
||||||
|
const resp = await axios({
|
||||||
|
method: "get",
|
||||||
|
url,
|
||||||
|
});
|
||||||
|
return resp.data;
|
||||||
|
}
|
||||||
|
|
||||||
export async function listActiveTasks(
|
export async function listActiveTasks(
|
||||||
qname: string,
|
qname: string,
|
||||||
pageOpts?: PaginationOptions
|
pageOpts?: PaginationOptions
|
||||||
|
|||||||
@@ -114,6 +114,9 @@ import {
|
|||||||
BATCH_DELETE_PENDING_TASKS_SUCCESS,
|
BATCH_DELETE_PENDING_TASKS_SUCCESS,
|
||||||
BATCH_ARCHIVE_PENDING_TASKS_ERROR,
|
BATCH_ARCHIVE_PENDING_TASKS_ERROR,
|
||||||
BATCH_DELETE_PENDING_TASKS_ERROR,
|
BATCH_DELETE_PENDING_TASKS_ERROR,
|
||||||
|
GET_TASK_INFO_BEGIN,
|
||||||
|
GET_TASK_INFO_ERROR,
|
||||||
|
GET_TASK_INFO_SUCCESS,
|
||||||
} from "../actions/tasksActions";
|
} from "../actions/tasksActions";
|
||||||
import {
|
import {
|
||||||
ActiveTask,
|
ActiveTask,
|
||||||
@@ -121,6 +124,7 @@ import {
|
|||||||
PendingTask,
|
PendingTask,
|
||||||
RetryTask,
|
RetryTask,
|
||||||
ScheduledTask,
|
ScheduledTask,
|
||||||
|
TaskInfo,
|
||||||
} from "../api";
|
} from "../api";
|
||||||
|
|
||||||
export interface ActiveTaskExtended extends ActiveTask {
|
export interface ActiveTaskExtended extends ActiveTask {
|
||||||
@@ -193,6 +197,11 @@ interface TasksState {
|
|||||||
error: string;
|
error: string;
|
||||||
data: ArchivedTaskExtended[];
|
data: ArchivedTaskExtended[];
|
||||||
};
|
};
|
||||||
|
taskInfo: {
|
||||||
|
loading: boolean;
|
||||||
|
error: string;
|
||||||
|
data?: TaskInfo;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: TasksState = {
|
const initialState: TasksState = {
|
||||||
@@ -231,6 +240,10 @@ const initialState: TasksState = {
|
|||||||
error: "",
|
error: "",
|
||||||
data: [],
|
data: [],
|
||||||
},
|
},
|
||||||
|
taskInfo: {
|
||||||
|
loading: false,
|
||||||
|
error: "",
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function tasksReducer(
|
function tasksReducer(
|
||||||
@@ -238,6 +251,34 @@ function tasksReducer(
|
|||||||
action: TasksActionTypes
|
action: TasksActionTypes
|
||||||
): TasksState {
|
): TasksState {
|
||||||
switch (action.type) {
|
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:
|
case LIST_ACTIVE_TASKS_BEGIN:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
|||||||
Reference in New Issue
Block a user