/**
* Updates the state storage depending on whether the saga is completed or keeps on running.
*/
private void updateStateStorage(final SagaInstanceDescription description) {
Saga saga = description.getSaga();
// if saga has finished delete existing state and possible timeouts
// if saga has just been created state has never been save and there
// is no need to delete it.
if (saga.isFinished() && !description.isStarting()) {
storage.delete(saga.state().getSagaId());
timeoutManager.cancelTimeouts(saga.state().getSagaId());
} else if (!saga.isFinished()) {
storage.save(saga.state());
}
}