Ejemplo n.º 1
0
        public async Task <IActionResult> Create(CreateStepCommand command, bool?wait_for_completion, string timeout = "30s")
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            try
            {
                command.CreatedBy = ClaimsUtility.GetId(User);
                var result = await Mediator.Send(command);

                Step step = (await Mediator.Send(new GetEntityQuery <Step>()
                {
                    Expression = s => s.Id == new Guid(result.ObjectRefId),
                    Exclude = (s) => s.Journal
                })).Result;


                if (wait_for_completion.HasValue && wait_for_completion.Value)
                {
                    var ms = DateTimeMathsUtility.GetMs(timeout);

                    while (!StepStatuses.IsCompleteStatus(step.Status) && stopwatch.ElapsedMilliseconds < ms)
                    {
                        step = (await Mediator.Send(new GetEntityQuery <Step>()
                        {
                            Expression = s => s.Id == new Guid(result.ObjectRefId)
                        })).Result;
                    }
                }


                return(Ok(new HttpCommandResult <Step>("step", result, step)));
            }
            catch (BaseException e)
            {
                Logger.LogError(e.Message);
                stopwatch.Stop();
                return(BadRequest(e.ToExceptionResult(stopwatch.ElapsedMilliseconds)));
            }
        }
Ejemplo n.º 2
0
        public override void ApplyCommandToState(BaseCommand command)
        {
            switch (command)
            {
            case UpdateClusterDetails t1:
                if (Settings == null)
                {
                    Settings = new ClusterSettings();
                }

                if (t1.Id != null)
                {
                    Id = t1.Id;
                }
                if (t1.AssignmentEnabled != null)
                {
                    Settings.AssignmentEnabled = t1.AssignmentEnabled.Value;
                }
                else if (t1.DefaultIfNull)
                {
                    Settings.AssignmentEnabled = true;
                }

                if (t1.Version != null)
                {
                    Version = t1.Version;
                }
                if (t1.EncryptionKeyHash != null)
                {
                    EncryptionKeyHash = t1.EncryptionKeyHash;
                }
                if (t1.EncryptionKeySalt != null)
                {
                    EncryptionKeySalt = t1.EncryptionKeySalt;
                }

                if (t1.AllowAutoRegistration != null)
                {
                    Settings.AllowAutoRegistration = t1.AllowAutoRegistration.Value;
                }
                else if (t1.DefaultIfNull)
                {
                    Settings.AllowAutoRegistration = true;
                }

                if (t1.Initialized != null)
                {
                    Initialized = t1.Initialized.Value;
                }
                if (t1.MetricRetentionPeriod != null)
                {
                    try {
                        DateTimeMathsUtility.GetMs(t1.MetricRetentionPeriod);
                        Settings.MetricRetentionPeriod = t1.MetricRetentionPeriod;
                    }
                    catch (InvalidTimeUnitException e)
                    {
                        throw e;
                    }
                }
                else if (t1.DefaultIfNull)
                {
                    Settings.MetricRetentionPeriod = "24h";
                }
                break;

            /*case UpdateLogicBlockLock t1:
             *  if (t1.Action == LockBlockActions.APPLY)
             *  {
             *      LockedLogicBlocks.Add(t1.Lock.WorkflowId + ":" + t1.Lock.LogicBlockId, t1.Lock);
             *  }
             *  else if (t1.Action == LockBlockActions.REMOVE)
             *  {
             *      if (LockedLogicBlocks.ContainsKey(t1.Lock.WorkflowId + ":" + t1.Lock.LogicBlockId))
             *      {
             *          if (LockedLogicBlocks[t1.Lock.WorkflowId + ":" + t1.Lock.LogicBlockId].LockerCode == t1.Lock.LockerCode)
             *          {
             *
             *              LockedLogicBlocks.Remove(t1.Lock.WorkflowId + ":" + t1.Lock.LogicBlockId);
             *          }
             *          else
             *          {
             *              throw new InvalidLogicBlockUnlockException("Logic block " + t1.Lock.WorkflowId + ":" + t1.Lock.LogicBlockId + " is held by a different locker code. Given " + t1.Lock.LockerCode + ", held by " + LockedLogicBlocks[t1.Lock.WorkflowId + ":" + t1.Lock.LogicBlockId].LockerCode);
             *          }
             *      }
             *      else
             *      {
             *          throw new InvalidLogicBlockUnlockException("Logic block " + t1.Lock.WorkflowId + ":" + t1.Lock.LogicBlockId + " does not exist for unlocking.");
             *      }
             *  }
             *  else
             *  {
             *      Console.WriteLine("Received a logic block update for " + t1.Lock.WorkflowId + " that did not contain a action");
             *  }
             *  break;
             */
            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 3
0
        public async Task CleanUpData()
        {
            while (true)
            {
                if (ClusterStateService.Initialized && _nodeStateService.Role == ConsensusCore.Domain.Enums.NodeState.Leader)
                {
                    var           page             = 0;
                    long          tickPosition     = 0;
                    long          totalMetricTicks = 0;
                    int           cleanedCount     = 0;
                    CommandResult result           = null;
                    do
                    {
                        if (_state.GetSettings != null)
                        {
                            var entities = await _entitiesRepository.GetAsync <MetricTick>((s) => s.Date < DateTime.Now.AddMilliseconds(-1 * DateTimeMathsUtility.GetMs(_state.GetSettings.MetricRetentionPeriod)));

                            try
                            {
                                foreach (var tick in entities)
                                {
                                    var startTime = DateTime.Now;
                                    result = await _mediator.Send(new DeleteEntityCommand <MetricTick>
                                    {
                                        Entity = tick
                                    });

                                    _logger.LogDebug("Cleanup of record " + result.ObjectRefId + " took " + (DateTime.Now - startTime).TotalMilliseconds + " total ticks.");
                                    // _logger.LogDebug("Deleted record " + result.ObjectRefId + ".");
                                }
                            }
                            catch (Exception e)
                            {
                                _logger.LogError("Encountered error while trying to delete record " + Environment.NewLine + e.StackTrace);
                            }
                        }
                        // }
                    }while (result != null && result.IsSuccessful);
                    await Task.Delay(30000);
                }
            }
        }