mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-09-16 19:51:38 +08:00
Add batch-delete, batch-run, delete-all, run-all functionalities for
scheduled and retry tasks
This commit is contained in:
@@ -15,8 +15,14 @@ import {
|
||||
} from "../actions/queuesActions";
|
||||
import {
|
||||
BATCH_DELETE_DEAD_TASKS_SUCCESS,
|
||||
BATCH_DELETE_RETRY_TASKS_SUCCESS,
|
||||
BATCH_DELETE_SCHEDULED_TASKS_SUCCESS,
|
||||
BATCH_RUN_DEAD_TASKS_SUCCESS,
|
||||
BATCH_RUN_RETRY_TASKS_SUCCESS,
|
||||
BATCH_RUN_SCHEDULED_TASKS_SUCCESS,
|
||||
DELETE_ALL_DEAD_TASKS_SUCCESS,
|
||||
DELETE_ALL_RETRY_TASKS_SUCCESS,
|
||||
DELETE_ALL_SCHEDULED_TASKS_SUCCESS,
|
||||
DELETE_DEAD_TASK_SUCCESS,
|
||||
DELETE_RETRY_TASK_SUCCESS,
|
||||
DELETE_SCHEDULED_TASK_SUCCESS,
|
||||
@@ -26,6 +32,8 @@ import {
|
||||
LIST_RETRY_TASKS_SUCCESS,
|
||||
LIST_SCHEDULED_TASKS_SUCCESS,
|
||||
RUN_ALL_DEAD_TASKS_SUCCESS,
|
||||
RUN_ALL_RETRY_TASKS_SUCCESS,
|
||||
RUN_ALL_SCHEDULED_TASKS_SUCCESS,
|
||||
RUN_DEAD_TASK_SUCCESS,
|
||||
TasksActionTypes,
|
||||
} from "../actions/tasksActions";
|
||||
@@ -188,6 +196,79 @@ function queuesReducer(
|
||||
return { ...state, data: newData };
|
||||
}
|
||||
|
||||
case BATCH_RUN_SCHEDULED_TASKS_SUCCESS: {
|
||||
const newData = state.data.map((queueInfo) => {
|
||||
if (queueInfo.name !== action.queue) {
|
||||
return queueInfo;
|
||||
}
|
||||
return {
|
||||
...queueInfo,
|
||||
currentStats: {
|
||||
...queueInfo.currentStats,
|
||||
pending:
|
||||
queueInfo.currentStats.pending +
|
||||
action.payload.pending_keys.length,
|
||||
scheduled:
|
||||
queueInfo.currentStats.scheduled -
|
||||
action.payload.pending_keys.length,
|
||||
},
|
||||
};
|
||||
});
|
||||
return { ...state, data: newData };
|
||||
}
|
||||
|
||||
case BATCH_DELETE_SCHEDULED_TASKS_SUCCESS: {
|
||||
const newData = state.data.map((queueInfo) => {
|
||||
if (queueInfo.name !== action.queue) {
|
||||
return queueInfo;
|
||||
}
|
||||
return {
|
||||
...queueInfo,
|
||||
currentStats: {
|
||||
...queueInfo.currentStats,
|
||||
scheduled:
|
||||
queueInfo.currentStats.scheduled -
|
||||
action.payload.deleted_keys.length,
|
||||
},
|
||||
};
|
||||
});
|
||||
return { ...state, data: newData };
|
||||
}
|
||||
|
||||
case RUN_ALL_SCHEDULED_TASKS_SUCCESS: {
|
||||
const newData = state.data.map((queueInfo) => {
|
||||
if (queueInfo.name !== action.queue) {
|
||||
return queueInfo;
|
||||
}
|
||||
return {
|
||||
...queueInfo,
|
||||
currentStats: {
|
||||
...queueInfo.currentStats,
|
||||
pending:
|
||||
queueInfo.currentStats.pending + queueInfo.currentStats.scheduled,
|
||||
scheduled: 0,
|
||||
},
|
||||
};
|
||||
});
|
||||
return { ...state, data: newData };
|
||||
}
|
||||
|
||||
case DELETE_ALL_SCHEDULED_TASKS_SUCCESS: {
|
||||
const newData = state.data.map((queueInfo) => {
|
||||
if (queueInfo.name !== action.queue) {
|
||||
return queueInfo;
|
||||
}
|
||||
return {
|
||||
...queueInfo,
|
||||
currentStats: {
|
||||
...queueInfo.currentStats,
|
||||
scheduled: 0,
|
||||
},
|
||||
};
|
||||
});
|
||||
return { ...state, data: newData };
|
||||
}
|
||||
|
||||
case DELETE_RETRY_TASK_SUCCESS: {
|
||||
const newData = state.data.map((queueInfo) => {
|
||||
if (queueInfo.name !== action.queue) {
|
||||
@@ -204,6 +285,77 @@ function queuesReducer(
|
||||
return { ...state, data: newData };
|
||||
}
|
||||
|
||||
case BATCH_RUN_RETRY_TASKS_SUCCESS: {
|
||||
const newData = state.data.map((queueInfo) => {
|
||||
if (queueInfo.name !== action.queue) {
|
||||
return queueInfo;
|
||||
}
|
||||
return {
|
||||
...queueInfo,
|
||||
currentStats: {
|
||||
...queueInfo.currentStats,
|
||||
pending:
|
||||
queueInfo.currentStats.pending +
|
||||
action.payload.pending_keys.length,
|
||||
retry:
|
||||
queueInfo.currentStats.retry - action.payload.pending_keys.length,
|
||||
},
|
||||
};
|
||||
});
|
||||
return { ...state, data: newData };
|
||||
}
|
||||
|
||||
case BATCH_DELETE_RETRY_TASKS_SUCCESS: {
|
||||
const newData = state.data.map((queueInfo) => {
|
||||
if (queueInfo.name !== action.queue) {
|
||||
return queueInfo;
|
||||
}
|
||||
return {
|
||||
...queueInfo,
|
||||
currentStats: {
|
||||
...queueInfo.currentStats,
|
||||
retry:
|
||||
queueInfo.currentStats.retry - action.payload.deleted_keys.length,
|
||||
},
|
||||
};
|
||||
});
|
||||
return { ...state, data: newData };
|
||||
}
|
||||
|
||||
case RUN_ALL_RETRY_TASKS_SUCCESS: {
|
||||
const newData = state.data.map((queueInfo) => {
|
||||
if (queueInfo.name !== action.queue) {
|
||||
return queueInfo;
|
||||
}
|
||||
return {
|
||||
...queueInfo,
|
||||
currentStats: {
|
||||
...queueInfo.currentStats,
|
||||
pending:
|
||||
queueInfo.currentStats.pending + queueInfo.currentStats.retry,
|
||||
retry: 0,
|
||||
},
|
||||
};
|
||||
});
|
||||
return { ...state, data: newData };
|
||||
}
|
||||
|
||||
case DELETE_ALL_RETRY_TASKS_SUCCESS: {
|
||||
const newData = state.data.map((queueInfo) => {
|
||||
if (queueInfo.name !== action.queue) {
|
||||
return queueInfo;
|
||||
}
|
||||
return {
|
||||
...queueInfo,
|
||||
currentStats: {
|
||||
...queueInfo.currentStats,
|
||||
retry: 0,
|
||||
},
|
||||
};
|
||||
});
|
||||
return { ...state, data: newData };
|
||||
}
|
||||
|
||||
case DELETE_DEAD_TASK_SUCCESS: {
|
||||
const newData = state.data.map((queueInfo) => {
|
||||
if (queueInfo.name !== action.queue) {
|
||||
|
@@ -4,12 +4,20 @@ import {
|
||||
} from "../actions/snackbarActions";
|
||||
import {
|
||||
BATCH_DELETE_DEAD_TASKS_SUCCESS,
|
||||
BATCH_DELETE_RETRY_TASKS_SUCCESS,
|
||||
BATCH_DELETE_SCHEDULED_TASKS_SUCCESS,
|
||||
BATCH_RUN_DEAD_TASKS_SUCCESS,
|
||||
BATCH_RUN_RETRY_TASKS_SUCCESS,
|
||||
BATCH_RUN_SCHEDULED_TASKS_SUCCESS,
|
||||
DELETE_ALL_DEAD_TASKS_SUCCESS,
|
||||
DELETE_ALL_RETRY_TASKS_SUCCESS,
|
||||
DELETE_ALL_SCHEDULED_TASKS_SUCCESS,
|
||||
DELETE_DEAD_TASK_SUCCESS,
|
||||
DELETE_RETRY_TASK_SUCCESS,
|
||||
DELETE_SCHEDULED_TASK_SUCCESS,
|
||||
RUN_ALL_DEAD_TASKS_SUCCESS,
|
||||
RUN_ALL_RETRY_TASKS_SUCCESS,
|
||||
RUN_ALL_SCHEDULED_TASKS_SUCCESS,
|
||||
RUN_DEAD_TASK_SUCCESS,
|
||||
TasksActionTypes,
|
||||
} from "../actions/tasksActions";
|
||||
@@ -51,6 +59,36 @@ function snackbarReducer(
|
||||
message: `Scheduled task ${action.taskKey} deleted`,
|
||||
};
|
||||
|
||||
case BATCH_RUN_SCHEDULED_TASKS_SUCCESS: {
|
||||
const n = action.payload.pending_keys.length;
|
||||
return {
|
||||
isOpen: true,
|
||||
message: `${n} scheduled ${
|
||||
n === 1 ? "task is" : "tasks are"
|
||||
} now pending`,
|
||||
};
|
||||
}
|
||||
|
||||
case BATCH_DELETE_SCHEDULED_TASKS_SUCCESS: {
|
||||
const n = action.payload.deleted_keys.length;
|
||||
return {
|
||||
isOpen: true,
|
||||
message: `${n} scheduled ${n === 1 ? "task" : "tasks"} deleted`,
|
||||
};
|
||||
}
|
||||
|
||||
case RUN_ALL_SCHEDULED_TASKS_SUCCESS:
|
||||
return {
|
||||
isOpen: true,
|
||||
message: "All scheduled tasks are now pending",
|
||||
};
|
||||
|
||||
case DELETE_ALL_SCHEDULED_TASKS_SUCCESS:
|
||||
return {
|
||||
isOpen: true,
|
||||
message: "All scheduled tasks deleted",
|
||||
};
|
||||
|
||||
case DELETE_RETRY_TASK_SUCCESS:
|
||||
return {
|
||||
isOpen: true,
|
||||
@@ -58,6 +96,34 @@ function snackbarReducer(
|
||||
message: `Retry task ${action.taskKey} deleted`,
|
||||
};
|
||||
|
||||
case BATCH_RUN_RETRY_TASKS_SUCCESS: {
|
||||
const n = action.payload.pending_keys.length;
|
||||
return {
|
||||
isOpen: true,
|
||||
message: `${n} retry ${n === 1 ? "task is" : "tasks are"} now pending`,
|
||||
};
|
||||
}
|
||||
|
||||
case BATCH_DELETE_RETRY_TASKS_SUCCESS: {
|
||||
const n = action.payload.deleted_keys.length;
|
||||
return {
|
||||
isOpen: true,
|
||||
message: `${n} retry ${n === 1 ? "task" : "tasks"} deleted`,
|
||||
};
|
||||
}
|
||||
|
||||
case RUN_ALL_RETRY_TASKS_SUCCESS:
|
||||
return {
|
||||
isOpen: true,
|
||||
message: "All retry tasks are now pending",
|
||||
};
|
||||
|
||||
case DELETE_ALL_RETRY_TASKS_SUCCESS:
|
||||
return {
|
||||
isOpen: true,
|
||||
message: "All retry tasks deleted",
|
||||
};
|
||||
|
||||
case DELETE_DEAD_TASK_SUCCESS:
|
||||
return {
|
||||
isOpen: true,
|
||||
@@ -69,7 +135,7 @@ function snackbarReducer(
|
||||
const n = action.payload.pending_keys.length;
|
||||
return {
|
||||
isOpen: true,
|
||||
message: `${n} Dead ${n === 1 ? "task is" : "tasks are"} now pending`,
|
||||
message: `${n} dead ${n === 1 ? "task is" : "tasks are"} now pending`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -77,7 +143,7 @@ function snackbarReducer(
|
||||
const n = action.payload.deleted_keys.length;
|
||||
return {
|
||||
isOpen: true,
|
||||
message: `${n} Dead ${n === 1 ? "task" : "tasks"} deleted`,
|
||||
message: `${n} dead ${n === 1 ? "task" : "tasks"} deleted`,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -90,7 +156,7 @@ function snackbarReducer(
|
||||
case DELETE_ALL_DEAD_TASKS_SUCCESS:
|
||||
return {
|
||||
isOpen: true,
|
||||
message: "All dead tasks delete",
|
||||
message: "All dead tasks deleted",
|
||||
};
|
||||
|
||||
default:
|
||||
|
@@ -42,6 +42,30 @@ import {
|
||||
RUN_ALL_DEAD_TASKS_BEGIN,
|
||||
RUN_ALL_DEAD_TASKS_ERROR,
|
||||
RUN_ALL_DEAD_TASKS_SUCCESS,
|
||||
BATCH_DELETE_RETRY_TASKS_ERROR,
|
||||
BATCH_RUN_RETRY_TASKS_ERROR,
|
||||
BATCH_DELETE_RETRY_TASKS_SUCCESS,
|
||||
BATCH_RUN_RETRY_TASKS_SUCCESS,
|
||||
BATCH_DELETE_RETRY_TASKS_BEGIN,
|
||||
BATCH_RUN_RETRY_TASKS_BEGIN,
|
||||
DELETE_ALL_RETRY_TASKS_ERROR,
|
||||
RUN_ALL_RETRY_TASKS_ERROR,
|
||||
DELETE_ALL_RETRY_TASKS_SUCCESS,
|
||||
RUN_ALL_RETRY_TASKS_SUCCESS,
|
||||
DELETE_ALL_RETRY_TASKS_BEGIN,
|
||||
RUN_ALL_RETRY_TASKS_BEGIN,
|
||||
BATCH_DELETE_SCHEDULED_TASKS_ERROR,
|
||||
BATCH_RUN_SCHEDULED_TASKS_ERROR,
|
||||
BATCH_DELETE_SCHEDULED_TASKS_SUCCESS,
|
||||
BATCH_RUN_SCHEDULED_TASKS_SUCCESS,
|
||||
BATCH_DELETE_SCHEDULED_TASKS_BEGIN,
|
||||
BATCH_RUN_SCHEDULED_TASKS_BEGIN,
|
||||
DELETE_ALL_SCHEDULED_TASKS_ERROR,
|
||||
RUN_ALL_SCHEDULED_TASKS_ERROR,
|
||||
DELETE_ALL_SCHEDULED_TASKS_SUCCESS,
|
||||
RUN_ALL_SCHEDULED_TASKS_SUCCESS,
|
||||
DELETE_ALL_SCHEDULED_TASKS_BEGIN,
|
||||
RUN_ALL_SCHEDULED_TASKS_BEGIN,
|
||||
} from "../actions/tasksActions";
|
||||
import {
|
||||
ActiveTask,
|
||||
@@ -404,6 +428,103 @@ function tasksReducer(
|
||||
},
|
||||
};
|
||||
|
||||
case RUN_ALL_SCHEDULED_TASKS_BEGIN:
|
||||
case DELETE_ALL_SCHEDULED_TASKS_BEGIN:
|
||||
return {
|
||||
...state,
|
||||
scheduledTasks: {
|
||||
...state.scheduledTasks,
|
||||
allActionPending: true,
|
||||
},
|
||||
};
|
||||
|
||||
case RUN_ALL_SCHEDULED_TASKS_SUCCESS:
|
||||
case DELETE_ALL_SCHEDULED_TASKS_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
scheduledTasks: {
|
||||
...state.scheduledTasks,
|
||||
allActionPending: false,
|
||||
data: [],
|
||||
},
|
||||
};
|
||||
|
||||
case RUN_ALL_SCHEDULED_TASKS_ERROR:
|
||||
case DELETE_ALL_SCHEDULED_TASKS_ERROR:
|
||||
return {
|
||||
...state,
|
||||
scheduledTasks: {
|
||||
...state.scheduledTasks,
|
||||
allActionPending: false,
|
||||
},
|
||||
};
|
||||
|
||||
case BATCH_RUN_SCHEDULED_TASKS_BEGIN:
|
||||
case BATCH_DELETE_SCHEDULED_TASKS_BEGIN:
|
||||
return {
|
||||
...state,
|
||||
scheduledTasks: {
|
||||
...state.scheduledTasks,
|
||||
batchActionPending: true,
|
||||
data: state.scheduledTasks.data.map((task) => {
|
||||
if (!action.taskKeys.includes(task.key)) {
|
||||
return task;
|
||||
}
|
||||
return {
|
||||
...task,
|
||||
requestPending: true,
|
||||
};
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
case BATCH_RUN_SCHEDULED_TASKS_SUCCESS: {
|
||||
const newData = state.scheduledTasks.data.filter(
|
||||
(task) => !action.payload.pending_keys.includes(task.key)
|
||||
);
|
||||
return {
|
||||
...state,
|
||||
scheduledTasks: {
|
||||
...state.scheduledTasks,
|
||||
batchActionPending: false,
|
||||
data: newData,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
case BATCH_DELETE_SCHEDULED_TASKS_SUCCESS: {
|
||||
const newData = state.scheduledTasks.data.filter(
|
||||
(task) => !action.payload.deleted_keys.includes(task.key)
|
||||
);
|
||||
return {
|
||||
...state,
|
||||
scheduledTasks: {
|
||||
...state.scheduledTasks,
|
||||
batchActionPending: false,
|
||||
data: newData,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
case BATCH_RUN_SCHEDULED_TASKS_ERROR:
|
||||
case BATCH_DELETE_SCHEDULED_TASKS_ERROR:
|
||||
return {
|
||||
...state,
|
||||
scheduledTasks: {
|
||||
...state.scheduledTasks,
|
||||
batchActionPending: false,
|
||||
data: state.scheduledTasks.data.map((task) => {
|
||||
if (!action.taskKeys.includes(task.key)) {
|
||||
return task;
|
||||
}
|
||||
return {
|
||||
...task,
|
||||
requestPending: false,
|
||||
};
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
case DELETE_RETRY_TASK_BEGIN:
|
||||
return {
|
||||
...state,
|
||||
@@ -443,6 +564,103 @@ function tasksReducer(
|
||||
},
|
||||
};
|
||||
|
||||
case RUN_ALL_RETRY_TASKS_BEGIN:
|
||||
case DELETE_ALL_RETRY_TASKS_BEGIN:
|
||||
return {
|
||||
...state,
|
||||
retryTasks: {
|
||||
...state.retryTasks,
|
||||
allActionPending: true,
|
||||
},
|
||||
};
|
||||
|
||||
case RUN_ALL_RETRY_TASKS_SUCCESS:
|
||||
case DELETE_ALL_RETRY_TASKS_SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
retryTasks: {
|
||||
...state.retryTasks,
|
||||
allActionPending: false,
|
||||
data: [],
|
||||
},
|
||||
};
|
||||
|
||||
case RUN_ALL_RETRY_TASKS_ERROR:
|
||||
case DELETE_ALL_RETRY_TASKS_ERROR:
|
||||
return {
|
||||
...state,
|
||||
retryTasks: {
|
||||
...state.retryTasks,
|
||||
allActionPending: false,
|
||||
},
|
||||
};
|
||||
|
||||
case BATCH_RUN_RETRY_TASKS_BEGIN:
|
||||
case BATCH_DELETE_RETRY_TASKS_BEGIN:
|
||||
return {
|
||||
...state,
|
||||
retryTasks: {
|
||||
...state.retryTasks,
|
||||
batchActionPending: true,
|
||||
data: state.retryTasks.data.map((task) => {
|
||||
if (!action.taskKeys.includes(task.key)) {
|
||||
return task;
|
||||
}
|
||||
return {
|
||||
...task,
|
||||
requestPending: true,
|
||||
};
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
case BATCH_RUN_RETRY_TASKS_SUCCESS: {
|
||||
const newData = state.retryTasks.data.filter(
|
||||
(task) => !action.payload.pending_keys.includes(task.key)
|
||||
);
|
||||
return {
|
||||
...state,
|
||||
retryTasks: {
|
||||
...state.retryTasks,
|
||||
batchActionPending: false,
|
||||
data: newData,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
case BATCH_DELETE_RETRY_TASKS_SUCCESS: {
|
||||
const newData = state.retryTasks.data.filter(
|
||||
(task) => !action.payload.deleted_keys.includes(task.key)
|
||||
);
|
||||
return {
|
||||
...state,
|
||||
retryTasks: {
|
||||
...state.retryTasks,
|
||||
batchActionPending: false,
|
||||
data: newData,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
case BATCH_RUN_RETRY_TASKS_ERROR:
|
||||
case BATCH_DELETE_RETRY_TASKS_ERROR:
|
||||
return {
|
||||
...state,
|
||||
retryTasks: {
|
||||
...state.retryTasks,
|
||||
batchActionPending: false,
|
||||
data: state.retryTasks.data.map((task) => {
|
||||
if (!action.taskKeys.includes(task.key)) {
|
||||
return task;
|
||||
}
|
||||
return {
|
||||
...task,
|
||||
requestPending: false,
|
||||
};
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
case RUN_DEAD_TASK_BEGIN:
|
||||
case DELETE_DEAD_TASK_BEGIN:
|
||||
return {
|
||||
|
Reference in New Issue
Block a user