[ML] Close job after forecast errors if starting from closed (#38253) (#38270)

* [ML] Close job after forecast errors if starting from closed

* [ML] Pass closeJob flag to error handler if forecast ID undefined
This commit is contained in:
Pete Harverson 2019-06-06 18:01:01 +01:00 committed by GitHub
parent b64d3ae123
commit 05757eb0b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -163,19 +163,40 @@ export const ForecastingModal = injectI18n(class ForecastingModal extends Compon
});
};
runForecastErrorHandler = (resp) => {
runForecastErrorHandler = (resp, closeJob) => {
const intl = this.props.intl;
this.setState({ forecastProgress: PROGRESS_STATES.ERROR });
console.log('Time series forecast modal - error running forecast:', resp);
if (resp && resp.message) {
this.addMessage(resp.message, MESSAGE_LEVEL.ERROR, true);
} else {
this.addMessage(
this.props.intl.formatMessage({
intl.formatMessage({
id: 'xpack.ml.timeSeriesExplorer.forecastingModal.unexpectedResponseFromRunningForecastErrorMessage',
defaultMessage: 'Unexpected response from running forecast. The request may have failed.',
}),
MESSAGE_LEVEL.ERROR, true);
}
if (closeJob === true) {
this.setState({ jobClosingState: PROGRESS_STATES.WAITING });
mlJobService.closeJob(this.props.job.job_id)
.then(() => {
this.setState({ jobClosingState: PROGRESS_STATES.DONE });
})
.catch((response) => {
console.log('Time series forecast modal - could not close job:', response);
this.addMessage(
intl.formatMessage({
id: 'xpack.ml.timeSeriesExplorer.forecastingModal.errorWithClosingJobErrorMessage',
defaultMessage: 'Error closing job',
}),
MESSAGE_LEVEL.ERROR
);
this.setState({ jobClosingState: PROGRESS_STATES.ERROR });
});
}
};
runForecast = (closeJobAfterRunning) => {
@ -194,10 +215,10 @@ export const ForecastingModal = injectI18n(class ForecastingModal extends Compon
if (resp.forecast_id !== undefined) {
this.waitForForecastResults(resp.forecast_id, closeJobAfterRunning);
} else {
this.runForecastErrorHandler(resp);
this.runForecastErrorHandler(resp, closeJobAfterRunning);
}
})
.catch(this.runForecastErrorHandler);
.catch(resp => this.runForecastErrorHandler(resp, closeJobAfterRunning));
};
waitForForecastResults = (forecastId, closeJobAfterRunning) => {