Skip to content

Commit 344efe6

Browse files
authored
792 clear previous log before switching extraction logs (#793)
* immediately update before the time interval refresh * add proper reset
1 parent 7a54520 commit 344efe6

File tree

4 files changed

+184
-64
lines changed

4 files changed

+184
-64
lines changed

frontend/src/actions/listeners.js

Lines changed: 109 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,202 @@
1-
import {V2} from "../openapi";
2-
import {handleErrors} from "./common";
1+
import { V2 } from "../openapi";
2+
import { handleErrors } from "./common";
33

44
export const RECEIVE_LISTENERS = "RECEIVE_LISTENERS";
55

6-
export function fetchListeners(skip=0, limit=21, category=null, label=null){
6+
export function fetchListeners(
7+
skip = 0,
8+
limit = 21,
9+
category = null,
10+
label = null
11+
) {
712
return (dispatch) => {
813
// TODO: Parameters for dates? paging?
9-
return V2.ListenersService.getListenersApiV2ListenersGet(skip, limit, category, label)
10-
.then(json => {
14+
return V2.ListenersService.getListenersApiV2ListenersGet(
15+
skip,
16+
limit,
17+
category,
18+
label
19+
)
20+
.then((json) => {
1121
dispatch({
1222
type: RECEIVE_LISTENERS,
1323
listeners: json,
1424
receivedAt: Date.now(),
1525
});
1626
})
17-
.catch(reason => {
18-
dispatch(handleErrors(reason, fetchListeners(skip, limit, category, label)));
27+
.catch((reason) => {
28+
dispatch(
29+
handleErrors(reason, fetchListeners(skip, limit, category, label))
30+
);
1931
});
20-
2132
};
2233
}
2334

2435
export const SEARCH_LISTENERS = "SEARCH_LISTENERS";
2536

26-
export function queryListeners(text, skip=0, limit=21){
37+
export function queryListeners(text, skip = 0, limit = 21) {
2738
return (dispatch) => {
2839
// TODO: Parameters for dates? paging?
29-
return V2.ListenersService.searchListenersApiV2ListenersSearchGet(text, skip, limit)
30-
.then(json => {
40+
return V2.ListenersService.searchListenersApiV2ListenersSearchGet(
41+
text,
42+
skip,
43+
limit
44+
)
45+
.then((json) => {
3146
dispatch({
3247
type: SEARCH_LISTENERS,
3348
listeners: json,
3449
receivedAt: Date.now(),
3550
});
3651
})
37-
.catch(reason => {
52+
.catch((reason) => {
3853
dispatch(handleErrors(reason, queryListeners(text, skip, limit)));
3954
});
40-
4155
};
4256
}
4357

4458
export const RECEIVE_LISTENER_CATEGORIES = "RECEIVE_LISTENER_CATEGORIES";
45-
export function fetchListenerCategories(){
59+
60+
export function fetchListenerCategories() {
4661
return (dispatch) => {
4762
return V2.ListenersService.listCategoriesApiV2ListenersCategoriesGet()
48-
.then(json => {
63+
.then((json) => {
4964
dispatch({
5065
type: RECEIVE_LISTENER_CATEGORIES,
5166
categories: json,
5267
receivedAt: Date.now(),
5368
});
5469
})
55-
.catch(reason => {
70+
.catch((reason) => {
5671
dispatch(handleErrors(reason, fetchListenerCategories()));
5772
});
58-
}
73+
};
5974
}
6075

6176
export const RECEIVE_LISTENER_LABELS = "RECEIVE_LISTENER_LABELS";
62-
export function fetchListenerLabels(){
77+
78+
export function fetchListenerLabels() {
6379
return (dispatch) => {
6480
return V2.ListenersService.listDefaultLabelsApiV2ListenersDefaultLabelsGet()
65-
.then(json => {
81+
.then((json) => {
6682
dispatch({
6783
type: RECEIVE_LISTENER_LABELS,
6884
labels: json,
6985
receivedAt: Date.now(),
7086
});
7187
})
72-
.catch(reason => {
88+
.catch((reason) => {
7389
dispatch(handleErrors(reason, fetchListenerLabels()));
7490
});
75-
}
91+
};
7692
}
7793

78-
7994
export const RECEIVE_LISTENER_JOBS = "RECEIVE_LISTENER_JOBS";
80-
export function fetchListenerJobs(listenerId, status, userId=null, fileId=null, datasetId = null,
81-
created, skip=0, limit=100){
95+
96+
export function fetchListenerJobs(
97+
listenerId,
98+
status,
99+
userId = null,
100+
fileId = null,
101+
datasetId = null,
102+
created,
103+
skip = 0,
104+
limit = 100
105+
) {
82106
return (dispatch) => {
83-
return V2.JobsService.getAllJobSummaryApiV2JobsGet(listenerId, status, userId, fileId, datasetId, created,
84-
skip, limit)
85-
.then(json => {
107+
return V2.JobsService.getAllJobSummaryApiV2JobsGet(
108+
listenerId,
109+
status,
110+
userId,
111+
fileId,
112+
datasetId,
113+
created,
114+
skip,
115+
limit
116+
)
117+
.then((json) => {
86118
dispatch({
87119
type: RECEIVE_LISTENER_JOBS,
88120
jobs: json,
89121
receivedAt: Date.now(),
90122
});
91123
})
92-
.catch(reason => {
93-
dispatch(handleErrors(reason, fetchListenerLabels(listenerId, status, userId=null, fileId=null,
94-
datasetId = null, created, skip=0, limit=100)));
124+
.catch((reason) => {
125+
dispatch(
126+
handleErrors(
127+
reason,
128+
fetchListenerLabels(
129+
listenerId,
130+
status,
131+
(userId = null),
132+
(fileId = null),
133+
(datasetId = null),
134+
created,
135+
(skip = 0),
136+
(limit = 100)
137+
)
138+
)
139+
);
95140
});
96-
}
141+
};
97142
}
98143

99-
100144
export const FETCH_JOB_SUMMARY = "FETCH_JOB_SUMMARY";
101-
export function fetchJobSummary(jobId){
145+
146+
export function fetchJobSummary(jobId) {
102147
return (dispatch) => {
103148
return V2.JobsService.getJobSummaryApiV2JobsJobIdSummaryGet(jobId)
104-
.then(json => {
149+
.then((json) => {
105150
dispatch({
106151
type: FETCH_JOB_SUMMARY,
107152
currJobSummary: json,
108153
receivedAt: Date.now(),
109154
});
110155
})
111-
.catch(reason => {
156+
.catch((reason) => {
112157
dispatch(handleErrors(reason, fetchListenerLabels()));
113158
});
114-
}
159+
};
115160
}
116161

162+
export const RESET_JOB_SUMMARY = "RESET_JOB_SUMMARY";
163+
164+
export function resetJobSummary() {
165+
return (dispatch) => {
166+
dispatch({
167+
type: RESET_JOB_SUMMARY,
168+
currJobSummary: {},
169+
receivedAt: Date.now(),
170+
});
171+
};
172+
}
117173

118174
export const FETCH_JOB_UPDATES = "FETCH_JOB_UPDATES";
119-
export function fetchJobUpdates(jobId){
175+
176+
export function fetchJobUpdates(jobId) {
120177
return (dispatch) => {
121178
return V2.JobsService.getJobUpdatesApiV2JobsJobIdUpdatesGet(jobId)
122-
.then(json => {
179+
.then((json) => {
123180
dispatch({
124181
type: FETCH_JOB_UPDATES,
125182
currJobUpdates: json,
126183
receivedAt: Date.now(),
127184
});
128185
})
129-
.catch(reason => {
186+
.catch((reason) => {
130187
dispatch(handleErrors(reason, fetchListenerLabels()));
131188
});
132-
}
189+
};
190+
}
191+
192+
export const RESET_JOB_UPDATES = "RESET_JOB_UPDATES";
193+
194+
export function resetJobUpdates() {
195+
return (dispatch) => {
196+
dispatch({
197+
type: RESET_JOB_UPDATES,
198+
currJobUpdates: [],
199+
receivedAt: Date.now(),
200+
});
201+
};
133202
}

frontend/src/components/listeners/ExtractorStatus.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp";
1515
import { parseDate } from "../../utils/common";
1616
import { useDispatch, useSelector } from "react-redux";
1717
import { RootState } from "../../types/data";
18-
import { fetchJobSummary, fetchJobUpdates } from "../../actions/listeners";
18+
import {
19+
fetchJobSummary,
20+
fetchJobUpdates,
21+
resetJobSummary,
22+
resetJobUpdates,
23+
} from "../../actions/listeners";
1924
import config from "../../app.config";
2025

2126
function Row(props: { summary: any; updates: any }) {
@@ -97,6 +102,8 @@ export default function ExtractorStatus(props: { job_id: any }) {
97102
dispatch(fetchJobSummary(job_id));
98103
const jobUpdatesFetch = (job_id: string | undefined) =>
99104
dispatch(fetchJobUpdates(job_id));
105+
const jobSummaryReset = () => dispatch(resetJobSummary());
106+
const jobUpdatesReset = () => dispatch(resetJobUpdates());
100107

101108
const summary = useSelector(
102109
(state: RootState) => state.listener.currJobSummary
@@ -106,6 +113,17 @@ export default function ExtractorStatus(props: { job_id: any }) {
106113
);
107114

108115
useEffect(() => {
116+
// clear previous job's log
117+
jobSummaryReset();
118+
jobUpdatesReset();
119+
120+
// immediate fetch
121+
if (job_id.length > 0) {
122+
jobSummaryFetch(job_id);
123+
jobUpdatesFetch(job_id);
124+
}
125+
126+
// set the interval to fetch the job's log
109127
const interval = setInterval(() => {
110128
if (job_id.length > 0) {
111129
jobSummaryFetch(job_id);

frontend/src/reducers/listeners.ts

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import {
2-
RECEIVE_LISTENERS, SEARCH_LISTENERS, RECEIVE_LISTENER_CATEGORIES,
3-
RECEIVE_LISTENER_LABELS, RECEIVE_LISTENER_JOBS, FETCH_JOB_SUMMARY, FETCH_JOB_UPDATES
2+
FETCH_JOB_SUMMARY,
3+
FETCH_JOB_UPDATES,
4+
RECEIVE_LISTENER_CATEGORIES,
5+
RECEIVE_LISTENER_JOBS,
6+
RECEIVE_LISTENER_LABELS,
7+
RECEIVE_LISTENERS,
8+
RESET_JOB_SUMMARY,
9+
RESET_JOB_UPDATES,
10+
SEARCH_LISTENERS,
411
} from "../actions/listeners";
512
import { SUBMIT_DATASET_EXTRACTION } from "../actions/dataset";
613
import { SUBMIT_FILE_EXTRACTION } from "../actions/file";
7-
import {DataAction} from "../types/action";
8-
import {ListenerState} from "../types/data";
14+
import { DataAction } from "../types/action";
15+
import { ListenerState } from "../types/data";
916

1017
const defaultState: ListenerState = {
1118
listeners: [],
@@ -14,31 +21,43 @@ const defaultState: ListenerState = {
1421
jobs: [],
1522
currJobSummary: [],
1623
currJobUpdates: [],
17-
currJobId: ""
24+
currJobId: "",
1825
};
1926

2027
const listeners = (state = defaultState, action: DataAction) => {
2128
switch (action.type) {
2229
case RECEIVE_LISTENERS:
23-
return Object.assign({}, state, {listeners: action.listeners});
30+
return Object.assign({}, state, { listeners: action.listeners });
2431
case SEARCH_LISTENERS:
25-
return Object.assign({}, state, {listeners: action.listeners});
32+
return Object.assign({}, state, { listeners: action.listeners });
2633
case RECEIVE_LISTENER_CATEGORIES:
27-
return Object.assign({}, state, {categories: action.categories});
34+
return Object.assign({}, state, { categories: action.categories });
2835
case RECEIVE_LISTENER_LABELS:
29-
return Object.assign({}, state, {labels: action.labels});
36+
return Object.assign({}, state, { labels: action.labels });
3037
case RECEIVE_LISTENER_JOBS:
31-
return Object.assign({}, state, {jobs: action.jobs});
32-
case FETCH_JOB_SUMMARY:
33-
return Object.assign({}, state, {currJobSummary: action.currJobSummary});
34-
case FETCH_JOB_UPDATES:
35-
return Object.assign({}, state, {currJobUpdates: action.currJobUpdates});
36-
case SUBMIT_DATASET_EXTRACTION:
37-
return Object.assign({}, state, {currJobId: action.job_id});
38-
case SUBMIT_FILE_EXTRACTION:
39-
return Object.assign({}, state, {currJobId: action.job_id});
40-
default:
41-
return state;
38+
return Object.assign({}, state, { jobs: action.jobs });
39+
case FETCH_JOB_SUMMARY:
40+
return Object.assign({}, state, {
41+
currJobSummary: action.currJobSummary,
42+
});
43+
case RESET_JOB_SUMMARY:
44+
return Object.assign({}, state, {
45+
currJobSummary: {},
46+
});
47+
case FETCH_JOB_UPDATES:
48+
return Object.assign({}, state, {
49+
currJobUpdates: action.currJobUpdates,
50+
});
51+
case RESET_JOB_UPDATES:
52+
return Object.assign({}, state, {
53+
currJobUpdates: action.currJobUpdates,
54+
});
55+
case SUBMIT_DATASET_EXTRACTION:
56+
return Object.assign({}, state, { currJobId: action.job_id });
57+
case SUBMIT_FILE_EXTRACTION:
58+
return Object.assign({}, state, { currJobId: action.job_id });
59+
default:
60+
return state;
4261
}
4362
};
4463

0 commit comments

Comments
 (0)