2020-11-24 22:54:00 +08:00
|
|
|
import {
|
|
|
|
LIST_QUEUES_SUCCESS,
|
|
|
|
LIST_QUEUES_BEGIN,
|
|
|
|
QueuesActionTypes,
|
|
|
|
PAUSE_QUEUE_BEGIN,
|
|
|
|
PAUSE_QUEUE_SUCCESS,
|
|
|
|
PAUSE_QUEUE_ERROR,
|
|
|
|
RESUME_QUEUE_BEGIN,
|
|
|
|
RESUME_QUEUE_ERROR,
|
|
|
|
RESUME_QUEUE_SUCCESS,
|
|
|
|
GET_QUEUE_SUCCESS,
|
2020-11-29 00:34:12 +08:00
|
|
|
DELETE_QUEUE_BEGIN,
|
|
|
|
DELETE_QUEUE_ERROR,
|
|
|
|
DELETE_QUEUE_SUCCESS,
|
2020-11-24 22:54:00 +08:00
|
|
|
} from "../actions/queuesActions";
|
|
|
|
import {
|
2020-12-13 23:51:40 +08:00
|
|
|
BATCH_DELETE_DEAD_TASKS_SUCCESS,
|
2020-12-19 22:07:23 +08:00
|
|
|
BATCH_DELETE_RETRY_TASKS_SUCCESS,
|
|
|
|
BATCH_DELETE_SCHEDULED_TASKS_SUCCESS,
|
2020-12-15 22:46:23 +08:00
|
|
|
BATCH_RUN_DEAD_TASKS_SUCCESS,
|
2020-12-19 22:07:23 +08:00
|
|
|
BATCH_RUN_RETRY_TASKS_SUCCESS,
|
|
|
|
BATCH_RUN_SCHEDULED_TASKS_SUCCESS,
|
2020-12-16 22:55:51 +08:00
|
|
|
DELETE_ALL_DEAD_TASKS_SUCCESS,
|
2020-12-19 22:07:23 +08:00
|
|
|
DELETE_ALL_RETRY_TASKS_SUCCESS,
|
|
|
|
DELETE_ALL_SCHEDULED_TASKS_SUCCESS,
|
2020-12-09 22:56:44 +08:00
|
|
|
DELETE_DEAD_TASK_SUCCESS,
|
2020-12-09 13:22:23 +08:00
|
|
|
DELETE_RETRY_TASK_SUCCESS,
|
2020-12-09 22:56:44 +08:00
|
|
|
DELETE_SCHEDULED_TASK_SUCCESS,
|
2020-11-24 22:54:00 +08:00
|
|
|
LIST_ACTIVE_TASKS_SUCCESS,
|
|
|
|
LIST_DEAD_TASKS_SUCCESS,
|
|
|
|
LIST_PENDING_TASKS_SUCCESS,
|
|
|
|
LIST_RETRY_TASKS_SUCCESS,
|
|
|
|
LIST_SCHEDULED_TASKS_SUCCESS,
|
2020-12-17 22:57:30 +08:00
|
|
|
RUN_ALL_DEAD_TASKS_SUCCESS,
|
2020-12-19 22:07:23 +08:00
|
|
|
RUN_ALL_RETRY_TASKS_SUCCESS,
|
|
|
|
RUN_ALL_SCHEDULED_TASKS_SUCCESS,
|
2020-12-14 23:14:10 +08:00
|
|
|
RUN_DEAD_TASK_SUCCESS,
|
2020-12-19 22:35:08 +08:00
|
|
|
RUN_RETRY_TASK_SUCCESS,
|
|
|
|
RUN_SCHEDULED_TASK_SUCCESS,
|
2020-11-24 22:54:00 +08:00
|
|
|
TasksActionTypes,
|
|
|
|
} from "../actions/tasksActions";
|
|
|
|
import { DailyStat, Queue } from "../api";
|
|
|
|
|
|
|
|
interface QueuesState {
|
|
|
|
loading: boolean;
|
|
|
|
data: QueueInfo[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface QueueInfo {
|
|
|
|
name: string; // name of the queue.
|
|
|
|
currentStats: Queue;
|
|
|
|
history: DailyStat[];
|
2020-11-29 00:34:12 +08:00
|
|
|
requestPending: boolean; // indicates pause/resume/delete action is pending on this queue
|
2020-11-24 22:54:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const initialState: QueuesState = { data: [], loading: false };
|
|
|
|
|
|
|
|
function queuesReducer(
|
|
|
|
state = initialState,
|
|
|
|
action: QueuesActionTypes | TasksActionTypes
|
|
|
|
): QueuesState {
|
|
|
|
switch (action.type) {
|
|
|
|
case LIST_QUEUES_BEGIN:
|
|
|
|
return { ...state, loading: true };
|
|
|
|
|
|
|
|
case LIST_QUEUES_SUCCESS:
|
|
|
|
const { queues } = action.payload;
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
loading: false,
|
|
|
|
data: queues.map((q: Queue) => ({
|
|
|
|
name: q.queue,
|
|
|
|
currentStats: q,
|
|
|
|
history: [],
|
2020-11-29 00:34:12 +08:00
|
|
|
requestPending: false,
|
2020-11-24 22:54:00 +08:00
|
|
|
})),
|
|
|
|
};
|
|
|
|
|
|
|
|
case GET_QUEUE_SUCCESS:
|
|
|
|
const newData = state.data
|
|
|
|
.filter((queueInfo) => queueInfo.name !== action.queue)
|
|
|
|
.concat({
|
|
|
|
name: action.queue,
|
|
|
|
currentStats: action.payload.current,
|
|
|
|
history: action.payload.history,
|
2020-11-29 00:34:12 +08:00
|
|
|
requestPending: false,
|
2020-11-24 22:54:00 +08:00
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
|
2020-11-29 00:34:12 +08:00
|
|
|
case DELETE_QUEUE_BEGIN:
|
2020-11-24 22:54:00 +08:00
|
|
|
case PAUSE_QUEUE_BEGIN:
|
|
|
|
case RESUME_QUEUE_BEGIN: {
|
|
|
|
const newData = state.data.map((queueInfo) => {
|
|
|
|
if (queueInfo.name !== action.queue) {
|
|
|
|
return queueInfo;
|
|
|
|
}
|
2020-11-29 00:34:12 +08:00
|
|
|
return { ...queueInfo, requestPending: true };
|
2020-11-24 22:54:00 +08:00
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
2020-11-29 00:34:12 +08:00
|
|
|
case DELETE_QUEUE_SUCCESS: {
|
|
|
|
const newData = state.data.filter(
|
|
|
|
(queueInfo) => queueInfo.name !== action.queue
|
|
|
|
);
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
2020-11-24 22:54:00 +08:00
|
|
|
case PAUSE_QUEUE_SUCCESS: {
|
|
|
|
const newData = state.data.map((queueInfo) => {
|
|
|
|
if (queueInfo.name !== action.queue) {
|
|
|
|
return queueInfo;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...queueInfo,
|
2020-11-29 00:34:12 +08:00
|
|
|
requestPending: false,
|
2020-11-24 22:54:00 +08:00
|
|
|
currentStats: { ...queueInfo.currentStats, paused: true },
|
|
|
|
};
|
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
|
|
|
case RESUME_QUEUE_SUCCESS: {
|
|
|
|
const newData = state.data.map((queueInfo) => {
|
|
|
|
if (queueInfo.name !== action.queue) {
|
|
|
|
return queueInfo;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...queueInfo,
|
2020-11-29 00:34:12 +08:00
|
|
|
requestPending: false,
|
2020-11-24 22:54:00 +08:00
|
|
|
currentStats: { ...queueInfo.currentStats, paused: false },
|
|
|
|
};
|
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
2020-11-29 00:34:12 +08:00
|
|
|
case DELETE_QUEUE_ERROR:
|
2020-11-24 22:54:00 +08:00
|
|
|
case PAUSE_QUEUE_ERROR:
|
|
|
|
case RESUME_QUEUE_ERROR: {
|
|
|
|
const newData = state.data.map((queueInfo) => {
|
|
|
|
if (queueInfo.name !== action.queue) {
|
|
|
|
return queueInfo;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...queueInfo,
|
2020-11-29 00:34:12 +08:00
|
|
|
requestPending: false,
|
2020-11-24 22:54:00 +08:00
|
|
|
};
|
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
|
|
|
case LIST_ACTIVE_TASKS_SUCCESS:
|
|
|
|
case LIST_PENDING_TASKS_SUCCESS:
|
|
|
|
case LIST_SCHEDULED_TASKS_SUCCESS:
|
|
|
|
case LIST_RETRY_TASKS_SUCCESS:
|
|
|
|
case LIST_DEAD_TASKS_SUCCESS: {
|
|
|
|
const newData = state.data
|
|
|
|
.filter((queueInfo) => queueInfo.name !== action.queue)
|
|
|
|
.concat({
|
|
|
|
name: action.queue,
|
|
|
|
currentStats: action.payload.stats,
|
|
|
|
history: [],
|
2020-11-29 00:34:12 +08:00
|
|
|
requestPending: false,
|
2020-11-24 22:54:00 +08:00
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
2020-12-19 22:35:08 +08:00
|
|
|
case RUN_SCHEDULED_TASK_SUCCESS: {
|
|
|
|
const newData = state.data.map((queueInfo) => {
|
|
|
|
if (queueInfo.name !== action.queue) {
|
|
|
|
return queueInfo;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...queueInfo,
|
|
|
|
currentStats: {
|
|
|
|
...queueInfo.currentStats,
|
|
|
|
pending: queueInfo.currentStats.pending + 1,
|
|
|
|
scheduled: queueInfo.currentStats.scheduled - 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
|
|
|
case RUN_RETRY_TASK_SUCCESS: {
|
|
|
|
const newData = state.data.map((queueInfo) => {
|
|
|
|
if (queueInfo.name !== action.queue) {
|
|
|
|
return queueInfo;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...queueInfo,
|
|
|
|
currentStats: {
|
|
|
|
...queueInfo.currentStats,
|
|
|
|
pending: queueInfo.currentStats.pending + 1,
|
|
|
|
retry: queueInfo.currentStats.retry - 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
2020-12-14 23:14:10 +08:00
|
|
|
case RUN_DEAD_TASK_SUCCESS: {
|
|
|
|
const newData = state.data.map((queueInfo) => {
|
|
|
|
if (queueInfo.name !== action.queue) {
|
|
|
|
return queueInfo;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...queueInfo,
|
|
|
|
currentStats: {
|
|
|
|
...queueInfo.currentStats,
|
|
|
|
pending: queueInfo.currentStats.pending + 1,
|
|
|
|
dead: queueInfo.currentStats.dead - 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
2020-12-09 22:56:44 +08:00
|
|
|
case DELETE_SCHEDULED_TASK_SUCCESS: {
|
|
|
|
const newData = state.data.map((queueInfo) => {
|
|
|
|
if (queueInfo.name !== action.queue) {
|
|
|
|
return queueInfo;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...queueInfo,
|
|
|
|
currentStats: {
|
|
|
|
...queueInfo.currentStats,
|
|
|
|
scheduled: queueInfo.currentStats.scheduled - 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
2020-12-19 22:07:23 +08:00
|
|
|
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 };
|
|
|
|
}
|
|
|
|
|
2020-12-09 13:22:23 +08:00
|
|
|
case DELETE_RETRY_TASK_SUCCESS: {
|
|
|
|
const newData = state.data.map((queueInfo) => {
|
|
|
|
if (queueInfo.name !== action.queue) {
|
|
|
|
return queueInfo;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...queueInfo,
|
|
|
|
currentStats: {
|
|
|
|
...queueInfo.currentStats,
|
|
|
|
retry: queueInfo.currentStats.retry - 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
2020-12-19 22:07:23 +08:00
|
|
|
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 };
|
|
|
|
}
|
|
|
|
|
2020-12-09 22:56:44 +08:00
|
|
|
case DELETE_DEAD_TASK_SUCCESS: {
|
|
|
|
const newData = state.data.map((queueInfo) => {
|
|
|
|
if (queueInfo.name !== action.queue) {
|
|
|
|
return queueInfo;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...queueInfo,
|
|
|
|
currentStats: {
|
|
|
|
...queueInfo.currentStats,
|
|
|
|
dead: queueInfo.currentStats.dead - 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
2020-12-15 22:46:23 +08:00
|
|
|
case BATCH_RUN_DEAD_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,
|
|
|
|
dead:
|
|
|
|
queueInfo.currentStats.dead - action.payload.pending_keys.length,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
2020-12-13 23:51:40 +08:00
|
|
|
case BATCH_DELETE_DEAD_TASKS_SUCCESS: {
|
|
|
|
const newData = state.data.map((queueInfo) => {
|
|
|
|
if (queueInfo.name !== action.queue) {
|
|
|
|
return queueInfo;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...queueInfo,
|
|
|
|
currentStats: {
|
|
|
|
...queueInfo.currentStats,
|
|
|
|
dead:
|
|
|
|
queueInfo.currentStats.dead - action.payload.deleted_keys.length,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
2020-12-17 22:57:30 +08:00
|
|
|
case RUN_ALL_DEAD_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.dead,
|
|
|
|
dead: 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
2020-12-16 22:55:51 +08:00
|
|
|
case DELETE_ALL_DEAD_TASKS_SUCCESS: {
|
|
|
|
const newData = state.data.map((queueInfo) => {
|
|
|
|
if (queueInfo.name !== action.queue) {
|
|
|
|
return queueInfo;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
...queueInfo,
|
|
|
|
currentStats: {
|
|
|
|
...queueInfo.currentStats,
|
|
|
|
dead: 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
return { ...state, data: newData };
|
|
|
|
}
|
|
|
|
|
2020-11-24 22:54:00 +08:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default queuesReducer;
|