diff options
| author | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-21 15:10:15 +0200 |
|---|---|---|
| committer | Georgios Andreadis <g.andreadis@student.tudelft.nl> | 2017-09-23 10:06:04 +0200 |
| commit | 0439ccf76f9ccf68c7572deadf38d6a157c439e7 (patch) | |
| tree | e71d3ac9b2ab443d8c49342cc6c7708ba2a00788 /src/sagas | |
| parent | da861719c6433a1fc9346da958f0907e52d578ce (diff) | |
Implement last-simulated-tick and states fetching
Diffstat (limited to 'src/sagas')
| -rw-r--r-- | src/sagas/experiments.js | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/src/sagas/experiments.js b/src/sagas/experiments.js index 29f9a211..5bcd6948 100644 --- a/src/sagas/experiments.js +++ b/src/sagas/experiments.js @@ -1,6 +1,17 @@ +import {delay} from "redux-saga"; import {call, put, select} from "redux-saga/effects"; import {addPropToStoreObject, addToStore} from "../actions/objects"; -import {deleteExperiment, getExperiment} from "../api/routes/experiments"; +import {setLastSimulatedTick} from "../actions/simulation/tick"; +import {addToStates} from "../actions/states"; +import { + deleteExperiment, + getAllMachineStates, + getAllRackStates, + getAllRoomStates, + getAllTaskStates, + getExperiment, + getLastSimulatedTick +} from "../api/routes/experiments"; import {getTasksOfJob} from "../api/routes/jobs"; import {addExperiment, getExperimentsOfSimulation, getSimulation} from "../api/routes/simulations"; import {getJobsOfTrace} from "../api/routes/traces"; @@ -19,11 +30,45 @@ export function* onOpenExperimentSucceeded(action) { yield fetchWorkloadOfTrace(experiment.traceId); yield fetchAllDatacentersOfExperiment(experiment); + yield startStateFetchLoop(action.experimentId); } catch (error) { console.error(error); } } +function* startStateFetchLoop(experimentId) { + try { + while (true) { + const lastSimulatedTick = (yield call(getLastSimulatedTick, experimentId)).lastSimulatedTick; + if (lastSimulatedTick !== (yield select(state => state.lastSimulatedTick))) { + yield put(setLastSimulatedTick(lastSimulatedTick)); + + const taskStates = yield call(getAllTaskStates, experimentId); + const machineStates = yield call(getAllMachineStates, experimentId); + const rackStates = yield call(getAllRackStates, experimentId); + const roomStates = yield call(getAllRoomStates, experimentId); + + yield addAllStates("task", taskStates); + yield addAllStates("machine", machineStates); + yield addAllStates("rack", rackStates); + yield addAllStates("room", roomStates); + + yield delay(5000); + } else { + yield delay(10000); + } + } + } catch (error) { + console.error(error); + } +} + +function* addAllStates(objectType, states) { + for (let i in states) { + yield put(addToStates(objectType, states[i].tick, states[i])); + } +} + export function* onFetchExperimentsOfSimulation() { try { const currentSimulationId = yield select(state => state.currentSimulationId); |
