Initial commit

This commit is contained in:
Ken Hibino
2020-11-24 06:54:00 -08:00
commit 7bd35a88e5
51 changed files with 16522 additions and 0 deletions

View File

@@ -0,0 +1,143 @@
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,
} from "../actions/queuesActions";
import {
LIST_ACTIVE_TASKS_SUCCESS,
LIST_DEAD_TASKS_SUCCESS,
LIST_PENDING_TASKS_SUCCESS,
LIST_RETRY_TASKS_SUCCESS,
LIST_SCHEDULED_TASKS_SUCCESS,
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[];
pauseRequestPending: boolean; // indicates pause/resume action is pending on this queue
}
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: [],
pauseRequestPending: false,
})),
};
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,
pauseRequestPending: false,
});
return { ...state, data: newData };
case PAUSE_QUEUE_BEGIN:
case RESUME_QUEUE_BEGIN: {
const newData = state.data.map((queueInfo) => {
if (queueInfo.name !== action.queue) {
return queueInfo;
}
return { ...queueInfo, pauseRequestPending: true };
});
return { ...state, data: newData };
}
case PAUSE_QUEUE_SUCCESS: {
const newData = state.data.map((queueInfo) => {
if (queueInfo.name !== action.queue) {
return queueInfo;
}
return {
...queueInfo,
pauseRequestPending: false,
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,
pauseRequestPending: false,
currentStats: { ...queueInfo.currentStats, paused: false },
};
});
return { ...state, data: newData };
}
case PAUSE_QUEUE_ERROR:
case RESUME_QUEUE_ERROR: {
const newData = state.data.map((queueInfo) => {
if (queueInfo.name !== action.queue) {
return queueInfo;
}
return {
...queueInfo,
pauseRequestPending: false,
};
});
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: [],
pauseRequestPending: false,
});
return { ...state, data: newData };
}
default:
return state;
}
}
export default queuesReducer;

View File

@@ -0,0 +1,26 @@
import {
POLL_INTERVAL_CHANGE,
SettingsActionTypes,
} from "../actions/settingsActions";
interface SettingsState {
pollInterval: number;
}
const initialState: SettingsState = {
pollInterval: 8,
};
function settingsReducer(
state = initialState,
action: SettingsActionTypes
): SettingsState {
switch (action.type) {
case POLL_INTERVAL_CHANGE:
return { ...state, pollInterval: action.value };
default:
return state;
}
}
export default settingsReducer;

View File

@@ -0,0 +1,243 @@
import {
LIST_ACTIVE_TASKS_BEGIN,
LIST_ACTIVE_TASKS_SUCCESS,
LIST_ACTIVE_TASKS_ERROR,
TasksActionTypes,
LIST_PENDING_TASKS_BEGIN,
LIST_PENDING_TASKS_SUCCESS,
LIST_PENDING_TASKS_ERROR,
LIST_SCHEDULED_TASKS_BEGIN,
LIST_SCHEDULED_TASKS_SUCCESS,
LIST_SCHEDULED_TASKS_ERROR,
LIST_RETRY_TASKS_BEGIN,
LIST_RETRY_TASKS_SUCCESS,
LIST_RETRY_TASKS_ERROR,
LIST_DEAD_TASKS_BEGIN,
LIST_DEAD_TASKS_SUCCESS,
LIST_DEAD_TASKS_ERROR,
} from "../actions/tasksActions";
import {
ActiveTask,
DeadTask,
PendingTask,
RetryTask,
ScheduledTask,
} from "../api";
interface TasksState {
activeTasks: {
loading: boolean;
error: string;
data: ActiveTask[];
};
pendingTasks: {
loading: boolean;
error: string;
data: PendingTask[];
};
scheduledTasks: {
loading: boolean;
error: string;
data: ScheduledTask[];
};
retryTasks: {
loading: boolean;
error: string;
data: RetryTask[];
};
deadTasks: {
loading: boolean;
error: string;
data: DeadTask[];
};
}
const initialState: TasksState = {
activeTasks: {
loading: false,
error: "",
data: [],
},
pendingTasks: {
loading: false,
error: "",
data: [],
},
scheduledTasks: {
loading: false,
error: "",
data: [],
},
retryTasks: {
loading: false,
error: "",
data: [],
},
deadTasks: {
loading: false,
error: "",
data: [],
},
};
function tasksReducer(
state = initialState,
action: TasksActionTypes
): TasksState {
switch (action.type) {
case LIST_ACTIVE_TASKS_BEGIN:
return {
...state,
activeTasks: {
...state.activeTasks,
error: "",
loading: true,
},
};
case LIST_ACTIVE_TASKS_SUCCESS:
return {
...state,
activeTasks: {
loading: false,
error: "",
data: action.payload.tasks,
},
};
case LIST_ACTIVE_TASKS_ERROR:
return {
...state,
activeTasks: {
...state.activeTasks,
loading: false,
error: action.error,
},
};
case LIST_PENDING_TASKS_BEGIN:
return {
...state,
pendingTasks: {
...state.pendingTasks,
error: "",
loading: true,
},
};
case LIST_PENDING_TASKS_SUCCESS:
return {
...state,
pendingTasks: {
loading: false,
error: "",
data: action.payload.tasks,
},
};
case LIST_PENDING_TASKS_ERROR:
return {
...state,
pendingTasks: {
...state.pendingTasks,
loading: false,
error: action.error,
},
};
case LIST_SCHEDULED_TASKS_BEGIN:
return {
...state,
scheduledTasks: {
...state.scheduledTasks,
error: "",
loading: true,
},
};
case LIST_SCHEDULED_TASKS_SUCCESS:
return {
...state,
scheduledTasks: {
loading: false,
error: "",
data: action.payload.tasks,
},
};
case LIST_SCHEDULED_TASKS_ERROR:
return {
...state,
scheduledTasks: {
...state.scheduledTasks,
loading: false,
error: action.error,
},
};
case LIST_RETRY_TASKS_BEGIN:
return {
...state,
retryTasks: {
...state.retryTasks,
error: "",
loading: true,
},
};
case LIST_RETRY_TASKS_SUCCESS:
return {
...state,
retryTasks: {
loading: false,
error: "",
data: action.payload.tasks,
},
};
case LIST_RETRY_TASKS_ERROR:
return {
...state,
retryTasks: {
...state.retryTasks,
loading: false,
error: action.error,
},
};
case LIST_DEAD_TASKS_BEGIN:
return {
...state,
deadTasks: {
...state.deadTasks,
error: "",
loading: true,
},
};
case LIST_DEAD_TASKS_SUCCESS:
return {
...state,
deadTasks: {
loading: false,
error: "",
data: action.payload.tasks,
},
};
case LIST_DEAD_TASKS_ERROR:
return {
...state,
deadTasks: {
...state.deadTasks,
loading: false,
error: action.error,
},
};
default:
return state;
}
}
export default tasksReducer;