Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
refactor(operations): dont repeat yourself
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Medina Sanchez committed Dec 21, 2017
1 parent 8213018 commit e839197
Showing 1 changed file with 17 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ <h3 class="title-desc">
Error: 2
};

function sendEvent(metricName, description, color){
document.dispatchEvent(new CustomEvent('HeadsUp', {
detail: {
title: metricName,
description: description,
date: new Date(),
url: '',
color: color
}
}));

firstTime = false;
}

function checkOperationMetricsToSendEvent(responseTimeState, errorsRateState, responseTimeAlertingLevels, errorsRateAlertingLevels){
var metricName = '';
var thresholds = '';
Expand All @@ -78,17 +92,7 @@ <h3 class="title-desc">
state = Math.max(errorsRateState, responseTimeState);
color = state == stateMapping['Error'] ? 'red' : state == stateMapping['Warn'] ? 'yellow' : 'blue';

document.dispatchEvent(new CustomEvent('HeadsUp', {
detail: {
title: metricName,
description: description,
date: new Date(),
url: '',
color: color
}
}));

firstTime = false;
sendEvent(metricName, description, color);
}

} else {
Expand All @@ -105,21 +109,10 @@ <h3 class="title-desc">
}

description = 'Greater than the threshold (' + thresholds + ')';

state = Math.max(errorsRateState, responseTimeState);
color = state == stateMapping['Error'] ? 'red' : state == stateMapping['Warn'] ? 'yellow' : 'blue';

document.dispatchEvent(new CustomEvent('HeadsUp', {
detail: {
title: metricName,
description: description,
date: new Date(),
url: '',
color: color
}
}));

firstTime = false;
sendEvent(metricName, description, color);
}
};

Expand All @@ -132,11 +125,9 @@ <h3 class="title-desc">
: metrics.errorsRate <= errorsRateAlertingLevels.error ? stateMapping['Warn']
: stateMapping['Error'];

var state = Math.max(responseTimeState, errorsRateState);

checkOperationMetricsToSendEvent(responseTimeState, errorsRateState, responseTimeAlertingLevels, errorsRateAlertingLevels);

return state;
return Math.max(responseTimeState, errorsRateState);
}

MGComponent({
Expand Down

0 comments on commit e839197

Please sign in to comment.