/// <summary> /// Validates a calculation and sets its state to running. It will then be fetched by the batchworker. /// </summary> /// <param name="calculation">The calculation.</param> /// <exception cref="System.Exception"></exception> public void Execute(Calculation calculation) { CheckDimensionLimits(calculation); if (!calculation.IsTransient) { // Rebind all values from the existing calculation calculation = calculationDepot.GetById(calculation.Id); calculation.StartDate = null; calculation.EndDate = null; calculation.EstimatedEndDate = null; var state = stateDepot.GetById(calculation.StateId); if (!State.ValidExecuteStates.Contains(state.Name)) { throw new Exception($"Invalid state {state.Name} for executing calculation."); } } var stateEnqueued = stateDepot.GetByName(State.NameEnqueued); calculation.StateId = stateEnqueued.Id; calculationDepot.Save(calculation); }
/// <summary> /// Restarts running but not completed calculations. /// </summary> public void ReEnqueueRunning() { App.Logger.Info("Reenqueue running calculations..."); var stateRunning = stateDepot.GetByName(State.NameRunning); var stateEnqueued = stateDepot.GetByName(State.NameEnqueued); var calculations = calculationDepot.GetByStateId(stateRunning.Id); foreach (var calculation in calculations) { App.Logger.Info($"Set calculation {calculation.Id} from state {stateRunning.Name} to {stateEnqueued.Name}."); calculation.StateId = stateEnqueued.Id; calculation.StartDate = null; calculation.EstimatedEndDate = null; calculation.EndDate = null; } calculationDepot.Save(calculations); }