Skip to content

Commit

Permalink
feat: implement scenario run duration tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
nborde-CSM committed Feb 16, 2022
1 parent 7c4ff05 commit 4fc8523
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/services/AppInsights.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AppInsightsSingleton {

trackScenarioRunDuration(runDuration) {
if (this.enabled) {
this.appInsights.trackMetric({ name: 'RunDurationValue', average: runDuration, sampleCount: runDuration });
this.appInsights.trackMetric({ name: 'RunDurationValue', average: runDuration });
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/state/sagas/scenario/LaunchScenario/LaunchScenario.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ export function* launchScenario(action) {
yield call(Api.ScenarioRuns.runScenario, ORGANIZATION_ID, workspaceId, scenarioId);

// Start backend polling to update the scenario status
const runStartTime = new Date().getTime();
yield put({
type: SCENARIO_ACTIONS_KEY.START_SCENARIO_STATUS_POLLING,
workspaceId: workspaceId,
scenarioId: scenarioId,
startTime: runStartTime,
});
} catch (e) {
console.error(e);
Expand Down
14 changes: 13 additions & 1 deletion src/state/sagas/scenario/PollScenarioState/PollScenarioState.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { SCENARIO_ACTIONS_KEY } from '../../../commons/ScenarioConstants';
import { ORGANIZATION_ID } from '../../../../config/AppInstance';
import { Api } from '../../../../services/config/Api';
import { SCENARIO_STATUS_POLLING_DELAY } from '../../../../config/AppConfiguration';
import { AppInsights } from '../../../../services/AppInsights';

const appInsights = AppInsights.getInstance();

function forgeStopPollingAction(scenarioId) {
let actionName = SCENARIO_ACTIONS_KEY.STOP_SCENARIO_STATUS_POLLING;
Expand All @@ -31,8 +34,17 @@ export function* pollScenarioState(action) {
// Update the scenario state in all scenario redux states
yield put({
type: SCENARIO_ACTIONS_KEY.UPDATE_SCENARIO,
data: { scenarioState: data.state, scenarioId: action.scenarioId, lastRun: data.lastRun },
data: {
scenarioState: data.state,
scenarioId: action.scenarioId,
lastRun: data.lastRun,
},
});
if (action.startTime) {
const runFinishTime = new Date().getTime();
const runDuration = (runFinishTime - action.startTime) / 1000;
appInsights.trackScenarioRunDuration(runDuration);
}
// Stop the polling for this scenario
yield put(forgeStopPollingAction(action.scenarioId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ export function* updateAndLaunchScenario(action) {
try {
appInsights.trackScenarioLaunch();
// Update scenario parameters
const runStartTime = new Date().getTime();
yield put({
type: SCENARIO_ACTIONS_KEY.SET_CURRENT_SCENARIO,
status: STATUSES.SAVING,
scenario: { state: SCENARIO_RUN_STATE.RUNNING, parametersValues: scenarioParameters },
scenario: {
state: SCENARIO_RUN_STATE.RUNNING,
parametersValues: scenarioParameters,
},
});
const { data: updateData } = yield call(
Api.Scenarios.updateScenario,
Expand All @@ -49,6 +53,7 @@ export function* updateAndLaunchScenario(action) {
type: SCENARIO_ACTIONS_KEY.START_SCENARIO_STATUS_POLLING,
workspaceId: workspaceId,
scenarioId: scenarioId,
startTime: runStartTime,
});
} catch (e) {
console.error(e);
Expand Down

0 comments on commit 4fc8523

Please sign in to comment.