mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-08-24 14:48:42 +08:00
Add run retry task, run scheduled task functionality
This commit is contained in:
@@ -29,6 +29,8 @@ import {
|
||||
runAllRetryTasks,
|
||||
runAllScheduledTasks,
|
||||
runDeadTask,
|
||||
runRetryTask,
|
||||
runScheduledTask,
|
||||
} from "../api";
|
||||
import { Dispatch } from "redux";
|
||||
|
||||
@@ -51,6 +53,12 @@ export const LIST_DEAD_TASKS_ERROR = "LIST_DEAD_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";
|
||||
export const RUN_SCHEDULED_TASK_BEGIN = "RUN_DEAD_TASK_BEGIN";
|
||||
export const RUN_SCHEDULED_TASK_SUCCESS = "RUN_DEAD_TASK_SUCCESS";
|
||||
export const RUN_SCHEDULED_TASK_ERROR = "RUN_DEAD_TASK_ERROR";
|
||||
export const RUN_RETRY_TASK_BEGIN = "RUN_RETRY_TASK_BEGIN";
|
||||
export const RUN_RETRY_TASK_SUCCESS = "RUN_RETRY_TASK_SUCCESS";
|
||||
export const RUN_RETRY_TASK_ERROR = "RUN_RETRY_TASK_ERROR";
|
||||
export const RUN_DEAD_TASK_BEGIN = "RUN_DEAD_TASK_BEGIN";
|
||||
export const RUN_DEAD_TASK_SUCCESS = "RUN_DEAD_TASK_SUCCESS";
|
||||
export const RUN_DEAD_TASK_ERROR = "RUN_DEAD_TASK_ERROR";
|
||||
@@ -215,6 +223,43 @@ interface CancelActiveTaskErrorAction {
|
||||
taskId: string;
|
||||
error: string;
|
||||
}
|
||||
interface RunScheduledTaskBeginAction {
|
||||
type: typeof RUN_SCHEDULED_TASK_BEGIN;
|
||||
queue: string;
|
||||
taskKey: string;
|
||||
}
|
||||
|
||||
interface RunScheduledTaskSuccessAction {
|
||||
type: typeof RUN_SCHEDULED_TASK_SUCCESS;
|
||||
queue: string;
|
||||
taskKey: string;
|
||||
}
|
||||
|
||||
interface RunScheduledTaskErrorAction {
|
||||
type: typeof RUN_SCHEDULED_TASK_ERROR;
|
||||
queue: string;
|
||||
taskKey: string;
|
||||
error: string;
|
||||
}
|
||||
|
||||
interface RunRetryTaskBeginAction {
|
||||
type: typeof RUN_RETRY_TASK_BEGIN;
|
||||
queue: string;
|
||||
taskKey: string;
|
||||
}
|
||||
|
||||
interface RunRetryTaskSuccessAction {
|
||||
type: typeof RUN_RETRY_TASK_SUCCESS;
|
||||
queue: string;
|
||||
taskKey: string;
|
||||
}
|
||||
|
||||
interface RunRetryTaskErrorAction {
|
||||
type: typeof RUN_RETRY_TASK_ERROR;
|
||||
queue: string;
|
||||
taskKey: string;
|
||||
error: string;
|
||||
}
|
||||
|
||||
interface RunDeadTaskBeginAction {
|
||||
type: typeof RUN_DEAD_TASK_BEGIN;
|
||||
@@ -522,6 +567,12 @@ export type TasksActionTypes =
|
||||
| CancelActiveTaskBeginAction
|
||||
| CancelActiveTaskSuccessAction
|
||||
| CancelActiveTaskErrorAction
|
||||
| RunScheduledTaskBeginAction
|
||||
| RunScheduledTaskSuccessAction
|
||||
| RunScheduledTaskErrorAction
|
||||
| RunRetryTaskBeginAction
|
||||
| RunRetryTaskSuccessAction
|
||||
| RunRetryTaskErrorAction
|
||||
| RunDeadTaskBeginAction
|
||||
| RunDeadTaskSuccessAction
|
||||
| RunDeadTaskErrorAction
|
||||
@@ -703,6 +754,42 @@ export function cancelActiveTaskAsync(queue: string, taskId: string) {
|
||||
};
|
||||
}
|
||||
|
||||
export function runScheduledTaskAsync(queue: string, taskKey: string) {
|
||||
return async (dispatch: Dispatch<TasksActionTypes>) => {
|
||||
dispatch({ type: RUN_SCHEDULED_TASK_BEGIN, queue, taskKey });
|
||||
try {
|
||||
await runScheduledTask(queue, taskKey);
|
||||
dispatch({ type: RUN_SCHEDULED_TASK_SUCCESS, queue, taskKey });
|
||||
} catch (error) {
|
||||
console.error("runScheduledTaskAsync: ", error);
|
||||
dispatch({
|
||||
type: RUN_SCHEDULED_TASK_ERROR,
|
||||
error: `Could not run task: ${taskKey}`,
|
||||
queue,
|
||||
taskKey,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function runRetryTaskAsync(queue: string, taskKey: string) {
|
||||
return async (dispatch: Dispatch<TasksActionTypes>) => {
|
||||
dispatch({ type: RUN_RETRY_TASK_BEGIN, queue, taskKey });
|
||||
try {
|
||||
await runRetryTask(queue, taskKey);
|
||||
dispatch({ type: RUN_RETRY_TASK_SUCCESS, queue, taskKey });
|
||||
} catch (error) {
|
||||
console.error("runRetryTaskAsync: ", error);
|
||||
dispatch({
|
||||
type: RUN_RETRY_TASK_ERROR,
|
||||
error: `Could not run task: ${taskKey}`,
|
||||
queue,
|
||||
taskKey,
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function runDeadTaskAsync(queue: string, taskKey: string) {
|
||||
return async (dispatch: Dispatch<TasksActionTypes>) => {
|
||||
dispatch({ type: RUN_DEAD_TASK_BEGIN, queue, taskKey });
|
||||
|
Reference in New Issue
Block a user