Skip to content

Commit

Permalink
Merge pull request #1 from USEPA/feature/remove-redis-from-webservice
Browse files Browse the repository at this point in the history
Feature/remove redis from webservice
  • Loading branch information
courtneymyers authored May 29, 2018
2 parents 9b2691f + c39b805 commit f51b032
Show file tree
Hide file tree
Showing 24 changed files with 140 additions and 2,080 deletions.
2 changes: 1 addition & 1 deletion epa-avert-webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion epa-avert-webapp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "epa-avert-webapp",
"version": "1.11.0",
"version": "1.12.0",
"private": true,
"description": "EPA's Avoided Emissions and Generation Tools (AVERT) is a free tool that estimates the emissions benefits of energy efficiency and renewable energy policies and programs.",
"author": "Eastern Research Group, Inc.",
Expand Down
1 change: 0 additions & 1 deletion epa-avert-webapp/src/app/redux/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export const SET_BASE_URL = 'api/SET_BASE_URL';
// reducer
const initialState = {
baseUrl: process.env.REACT_APP_URL,
pollingFrequency: 5000,
};

export default function reducer(state = initialState, action) {
Expand Down
61 changes: 8 additions & 53 deletions epa-avert-webapp/src/app/redux/co2.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { incrementProgress } from 'app/redux/annualDisplacement';
export const REQUEST_CO2 = 'co2/REQUEST_CO2';
export const RECEIVE_CO2 = 'co2/RECEIVE_CO2';
export const RECEIVE_ERROR = 'co2/RECEIVE_ERROR';
export const RECEIVE_JOB_ID = 'co2/RECEIVE_JOB_ID';
export const POLL_SERVER_FOR_DATA = 'co2/POLL_SERVER_FOR_DATA';

// reducer
const initialState = {
Expand Down Expand Up @@ -42,66 +40,19 @@ export default function reducer(state = initialState, action) {
error: true,
};

case RECEIVE_JOB_ID:
return {
...state,
jobId: action.jobId,
};

default:
return state;
}
}

// action creators
export const pollServerForData = () => {
return (dispatch, getState) => {
const { api, co2 } = getState();

dispatch({
type: POLL_SERVER_FOR_DATA,
jobId: co2.jobId,
});

const headers = new Headers();
headers.append('pragma', 'no-cache');
headers.append('cache-control', 'no-cache');

// fetch co2 data via job id
return fetch(`${api.baseUrl}/api/v1/jobs/${co2.jobId}`, {
headers: headers,
})
.then((response) => response.json())
.then((json) => {
if (json.response === 'error') {
dispatch({ type: RECEIVE_ERROR });
}

if (json.response === 'processing') {
return setTimeout(
() => dispatch(pollServerForData()),
api.pollingFrequency,
);
}

if (json.response === 'ok') {
dispatch(incrementProgress());
dispatch({
type: RECEIVE_CO2,
json: json,
});
}
});
};
};

export const fetchCo2 = () => {
return (dispatch, getState) => {
const { api } = getState();

dispatch({ type: REQUEST_CO2 });

// post co2 data for region and receive a job id
// post co2 data for region and receive calculated displacement data
const options = {
method: 'POST',
headers: {
Expand All @@ -113,14 +64,18 @@ export const fetchCo2 = () => {
eere: avert.eereLoad.hourlyEere,
}),
};

return fetch(`${api.baseUrl}/api/v1/co2`, options)
.then((response) => response.json())
.then((json) => {
dispatch(incrementProgress());
dispatch({
type: RECEIVE_JOB_ID,
jobId: json.jobId,
type: RECEIVE_CO2,
json: json,
});
dispatch(pollServerForData());
})
.catch((error) => {
dispatch({ type: RECEIVE_ERROR });
});
};
};
61 changes: 8 additions & 53 deletions epa-avert-webapp/src/app/redux/generation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { incrementProgress } from 'app/redux/annualDisplacement';
export const REQUEST_GENERATION = 'generation/REQUEST_GENERATION';
export const RECEIVE_GENERATION = 'generation/RECEIVE_GENERATION';
export const RECEIVE_ERROR = 'generation/RECEIVE_ERROR';
export const RECEIVE_JOB_ID = 'generation/RECEIVE_JOB_ID';
export const POLL_SERVER_FOR_DATA = 'generation/POLL_SERVER_FOR_DATA';

// reducer
const initialState = {
Expand Down Expand Up @@ -42,66 +40,19 @@ export default function reducer(state = initialState, action) {
error: true,
};

case RECEIVE_JOB_ID:
return {
...state,
jobId: action.jobId,
};

default:
return state;
}
}

// action creators
export const pollServerForData = () => {
return (dispatch, getState) => {
const { api, generation } = getState();

dispatch({
type: POLL_SERVER_FOR_DATA,
jobId: generation.jobId,
});

const headers = new Headers();
headers.append('pragma', 'no-cache');
headers.append('cache-control', 'no-cache');

// fetch generation data via job id
return fetch(`${api.baseUrl}/api/v1/jobs/${generation.jobId}`, {
headers: headers,
})
.then((response) => response.json())
.then((json) => {
if (json.response === 'error') {
dispatch({ type: RECEIVE_ERROR });
}

if (json.response === 'processing') {
return setTimeout(
() => dispatch(pollServerForData()),
api.pollingFrequency,
);
}

if (json.response === 'ok') {
dispatch(incrementProgress());
dispatch({
type: RECEIVE_GENERATION,
json: json,
});
}
});
};
};

export const fetchGeneration = () => {
return (dispatch, getState) => {
const { api } = getState();

dispatch({ type: REQUEST_GENERATION });

// post generation data for region and receive a job id
// post generation data for region and receive calculated displacement data
const options = {
method: 'POST',
headers: {
Expand All @@ -113,14 +64,18 @@ export const fetchGeneration = () => {
eere: avert.eereLoad.hourlyEere,
}),
};

return fetch(`${api.baseUrl}/api/v1/generation`, options)
.then((response) => response.json())
.then((json) => {
dispatch(incrementProgress());
dispatch({
type: RECEIVE_JOB_ID,
jobId: json.jobId,
type: RECEIVE_GENERATION,
json: json,
});
dispatch(pollServerForData());
})
.catch((error) => {
dispatch({ type: RECEIVE_ERROR });
});
};
};
61 changes: 8 additions & 53 deletions epa-avert-webapp/src/app/redux/nox.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { incrementProgress } from 'app/redux/annualDisplacement';
export const REQUEST_NOX = 'nox/REQUEST_NOX';
export const RECEIVE_NOX = 'nox/RECEIVE_NOX';
export const RECEIVE_ERROR = 'nox/RECEIVE_ERROR';
export const RECEIVE_JOB_ID = 'nox/RECEIVE_JOB_ID';
export const POLL_SERVER_FOR_DATA = 'nox/POLL_SERVER_FOR_DATA';

// reducer
const initialState = {
Expand Down Expand Up @@ -42,66 +40,19 @@ export default function reducer(state = initialState, action) {
error: true,
};

case RECEIVE_JOB_ID:
return {
...state,
jobId: action.jobId,
};

default:
return state;
}
}

// action creators
export const pollServerForData = () => {
return (dispatch, getState) => {
const { api, nox } = getState();

dispatch({
type: POLL_SERVER_FOR_DATA,
jobId: nox.jobId,
});

const headers = new Headers();
headers.append('pragma', 'no-cache');
headers.append('cache-control', 'no-cache');

// fetch nox data via job id
return fetch(`${api.baseUrl}/api/v1/jobs/${nox.jobId}`, {
headers: headers,
})
.then((response) => response.json())
.then((json) => {
if (json.response === 'error') {
dispatch({ type: RECEIVE_ERROR });
}

if (json.response === 'processing') {
return setTimeout(
() => dispatch(pollServerForData()),
api.pollingFrequency,
);
}

if (json.response === 'ok') {
dispatch(incrementProgress());
dispatch({
type: RECEIVE_NOX,
json: json,
});
}
});
};
};

export const fetchNox = () => {
return (dispatch, getState) => {
const { api } = getState();

dispatch({ type: REQUEST_NOX });

// post nox data for region and receive a job id
// post nox data for region and receive calculated displacement data
const options = {
method: 'POST',
headers: {
Expand All @@ -113,14 +64,18 @@ export const fetchNox = () => {
eere: avert.eereLoad.hourlyEere,
}),
};

return fetch(`${api.baseUrl}/api/v1/nox`, options)
.then((response) => response.json())
.then((json) => {
dispatch(incrementProgress());
dispatch({
type: RECEIVE_JOB_ID,
jobId: json.jobId,
type: RECEIVE_NOX,
json: json,
});
dispatch(pollServerForData());
})
.catch((error) => {
dispatch({ type: RECEIVE_ERROR });
});
};
};
Loading

0 comments on commit f51b032

Please sign in to comment.