2020-12-10 23:06:54 +08:00
|
|
|
import {
|
|
|
|
CLOSE_SNACKBAR,
|
|
|
|
SnackbarActionTypes,
|
|
|
|
} from "../actions/snackbarActions";
|
|
|
|
import {
|
2020-12-23 22:59:44 +08:00
|
|
|
BATCH_CANCEL_ACTIVE_TASKS_SUCCESS,
|
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-19 23:38:23 +08:00
|
|
|
BATCH_KILL_RETRY_TASKS_SUCCESS,
|
|
|
|
BATCH_KILL_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-23 22:59:44 +08:00
|
|
|
CANCEL_ALL_ACTIVE_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-10 23:06:54 +08:00
|
|
|
DELETE_DEAD_TASK_SUCCESS,
|
|
|
|
DELETE_RETRY_TASK_SUCCESS,
|
|
|
|
DELETE_SCHEDULED_TASK_SUCCESS,
|
2020-12-19 23:38:23 +08:00
|
|
|
KILL_ALL_RETRY_TASKS_SUCCESS,
|
|
|
|
KILL_ALL_SCHEDULED_TASKS_SUCCESS,
|
|
|
|
KILL_RETRY_TASK_SUCCESS,
|
|
|
|
KILL_SCHEDULED_TASK_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-12-10 23:06:54 +08:00
|
|
|
TasksActionTypes,
|
|
|
|
} from "../actions/tasksActions";
|
|
|
|
|
|
|
|
interface SnackbarState {
|
|
|
|
isOpen: boolean;
|
|
|
|
message: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const initialState: SnackbarState = {
|
|
|
|
isOpen: false,
|
|
|
|
message: "",
|
|
|
|
};
|
|
|
|
|
|
|
|
function snackbarReducer(
|
|
|
|
state = initialState,
|
|
|
|
action: TasksActionTypes | SnackbarActionTypes
|
|
|
|
): SnackbarState {
|
|
|
|
switch (action.type) {
|
|
|
|
case CLOSE_SNACKBAR:
|
|
|
|
return {
|
|
|
|
// Note: We keep the message state unchanged for
|
|
|
|
// smoother transition animation.
|
|
|
|
...state,
|
|
|
|
isOpen: false,
|
|
|
|
};
|
|
|
|
|
2020-12-23 22:59:44 +08:00
|
|
|
case BATCH_CANCEL_ACTIVE_TASKS_SUCCESS: {
|
|
|
|
const n = action.payload.canceled_ids.length;
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
|
|
|
message: `Cancelation signal sent to ${n} ${
|
|
|
|
n === 1 ? "task" : "tasks"
|
|
|
|
}`,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
case CANCEL_ALL_ACTIVE_TASKS_SUCCESS:
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
|
|
|
message: `Cancelation signal sent to all tasks in ${action.queue} queue`,
|
|
|
|
};
|
|
|
|
|
2020-12-19 22:35:08 +08:00
|
|
|
case RUN_SCHEDULED_TASK_SUCCESS:
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
2020-12-21 22:51:07 +08:00
|
|
|
message: `Scheduled task is now pending`,
|
2020-12-19 22:35:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
case RUN_RETRY_TASK_SUCCESS:
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
2020-12-21 22:51:07 +08:00
|
|
|
message: `Retry task is now pending`,
|
2020-12-19 22:35:08 +08:00
|
|
|
};
|
|
|
|
|
2020-12-14 23:14:10 +08:00
|
|
|
case RUN_DEAD_TASK_SUCCESS:
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
2020-12-21 22:51:07 +08:00
|
|
|
message: `Dead task is now pending`,
|
2020-12-14 23:14:10 +08:00
|
|
|
};
|
|
|
|
|
2020-12-19 23:38:23 +08:00
|
|
|
case KILL_SCHEDULED_TASK_SUCCESS:
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
2020-12-21 22:51:07 +08:00
|
|
|
message: `Scheduled task is now dead`,
|
2020-12-19 23:38:23 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
case KILL_RETRY_TASK_SUCCESS:
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
2020-12-21 22:51:07 +08:00
|
|
|
message: `Retry task is now dead`,
|
2020-12-19 23:38:23 +08:00
|
|
|
};
|
|
|
|
|
2020-12-10 23:06:54 +08:00
|
|
|
case DELETE_SCHEDULED_TASK_SUCCESS:
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
2020-12-21 22:51:07 +08:00
|
|
|
message: `Scheduled task deleted`,
|
2020-12-10 23:06:54 +08:00
|
|
|
};
|
|
|
|
|
2020-12-19 22:07:23 +08:00
|
|
|
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`,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-19 23:38:23 +08:00
|
|
|
case BATCH_KILL_SCHEDULED_TASKS_SUCCESS: {
|
|
|
|
const n = action.payload.dead_keys.length;
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
|
|
|
message: `${n} scheduled ${n === 1 ? "task is" : "tasks are"} now dead`,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-19 22:07:23 +08:00
|
|
|
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",
|
|
|
|
};
|
|
|
|
|
2020-12-19 23:38:23 +08:00
|
|
|
case KILL_ALL_SCHEDULED_TASKS_SUCCESS:
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
|
|
|
message: "All scheduled tasks are now dead",
|
|
|
|
};
|
|
|
|
|
2020-12-19 22:07:23 +08:00
|
|
|
case DELETE_ALL_SCHEDULED_TASKS_SUCCESS:
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
|
|
|
message: "All scheduled tasks deleted",
|
|
|
|
};
|
|
|
|
|
2020-12-10 23:06:54 +08:00
|
|
|
case DELETE_RETRY_TASK_SUCCESS:
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
2020-12-21 22:51:07 +08:00
|
|
|
message: `Retry task deleted`,
|
2020-12-10 23:06:54 +08:00
|
|
|
};
|
|
|
|
|
2020-12-19 22:07:23 +08:00
|
|
|
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`,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-19 23:38:23 +08:00
|
|
|
case BATCH_KILL_RETRY_TASKS_SUCCESS: {
|
|
|
|
const n = action.payload.dead_keys.length;
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
|
|
|
message: `${n} retry ${n === 1 ? "task is" : "tasks are"} now dead`,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-19 22:07:23 +08:00
|
|
|
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",
|
|
|
|
};
|
|
|
|
|
2020-12-19 23:38:23 +08:00
|
|
|
case KILL_ALL_RETRY_TASKS_SUCCESS:
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
|
|
|
message: "All retry tasks are now dead",
|
|
|
|
};
|
|
|
|
|
2020-12-19 22:07:23 +08:00
|
|
|
case DELETE_ALL_RETRY_TASKS_SUCCESS:
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
|
|
|
message: "All retry tasks deleted",
|
|
|
|
};
|
|
|
|
|
2020-12-10 23:06:54 +08:00
|
|
|
case DELETE_DEAD_TASK_SUCCESS:
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
2020-12-21 22:51:07 +08:00
|
|
|
message: `Dead task deleted`,
|
2020-12-10 23:06:54 +08:00
|
|
|
};
|
|
|
|
|
2020-12-15 22:46:23 +08:00
|
|
|
case BATCH_RUN_DEAD_TASKS_SUCCESS: {
|
|
|
|
const n = action.payload.pending_keys.length;
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
2020-12-19 22:07:23 +08:00
|
|
|
message: `${n} dead ${n === 1 ? "task is" : "tasks are"} now pending`,
|
2020-12-15 22:46:23 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-13 23:51:40 +08:00
|
|
|
case BATCH_DELETE_DEAD_TASKS_SUCCESS: {
|
|
|
|
const n = action.payload.deleted_keys.length;
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
2020-12-19 22:07:23 +08:00
|
|
|
message: `${n} dead ${n === 1 ? "task" : "tasks"} deleted`,
|
2020-12-13 23:51:40 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-12-17 22:57:30 +08:00
|
|
|
case RUN_ALL_DEAD_TASKS_SUCCESS:
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
|
|
|
message: "All dead tasks are now pending",
|
|
|
|
};
|
|
|
|
|
2020-12-16 22:55:51 +08:00
|
|
|
case DELETE_ALL_DEAD_TASKS_SUCCESS:
|
|
|
|
return {
|
|
|
|
isOpen: true,
|
2020-12-19 22:07:23 +08:00
|
|
|
message: "All dead tasks deleted",
|
2020-12-16 22:55:51 +08:00
|
|
|
};
|
|
|
|
|
2020-12-10 23:06:54 +08:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default snackbarReducer;
|