private async Task EnqueueFromSnapshotsAsync(IRuleEntity rule) { var errors = 0; await foreach (var(job, ex) in ruleService.CreateSnapshotJobsAsync(rule.RuleDef, rule.Id, rule.AppId.Id)) { if (job != null) { await ruleEventRepository.EnqueueAsync(job, ex); } else if (ex != null) { errors++; if (errors >= MaxErrors) { throw ex; } log.LogWarning(ex, w => w .WriteProperty("action", "runRule") .WriteProperty("status", "failedPartially")); } } }
public async Task <IEnrichedRuleEntity> EnrichAsync(IRuleEntity rule, Context context) { Guard.NotNull(rule, nameof(rule)); var enriched = await EnrichAsync(Enumerable.Repeat(rule, 1), context); return(enriched[0]); }
public async Task <IEnrichedRuleEntity> EnrichAsync(IRuleEntity rule, Context context, CancellationToken ct) { Guard.NotNull(rule); var enriched = await EnrichAsync(Enumerable.Repeat(rule, 1), context, ct); return(enriched[0]); }
private static RuleContext GetContext(IRuleEntity rule) { return(new RuleContext { AppId = rule.AppId, Rule = rule.RuleDef, RuleId = rule.Id }); }
public static void UpdateModelStateWithViolations(this Controller current, IRuleEntity entity, ModelStateDictionary modelState) { List<RuleViolation> productIssues = entity.GetRuleViolations(); foreach (var issue in productIssues) { modelState.AddModelError(issue.PropertyName, issue.ErrorMessage); } }
public static void UpdateModelStateWithViolations(this Controller current, IRuleEntity entity, ModelStateDictionary modelState) { List <RuleViolation> productIssues = entity.GetRuleViolations(); foreach (var issue in productIssues) { modelState.AddModelError(issue.PropertyName, issue.ErrorMessage); } }
public static void UpdateModelStateWithRuleViolations(IRuleEntity entity, ModelStateDictionary modelState) { List<RuleViolation> issues = entity.GetRuleViolations(); foreach (var issue in issues) { modelState.AddModelError(issue.PropertyName, issue.ErrorMessage); } }
public static RuleDto FromRule(IRuleEntity rule, ApiController controller, string app) { var result = new RuleDto(); SimpleMapper.Map(rule, result); SimpleMapper.Map(rule.RuleDef, result); if (rule.RuleDef.Trigger != null) { result.Trigger = RuleTriggerDtoFactory.Create(rule.RuleDef.Trigger); } return(result.CreateLinks(controller, app)); }
public static RuleDto FromRule(IRuleEntity rule) { var response = new RuleDto(); SimpleMapper.Map(rule, response); SimpleMapper.Map(rule.RuleDef, response); if (rule.RuleDef.Trigger != null) { response.Trigger = RuleTriggerDtoFactory.Create(rule.RuleDef.Trigger); } return(response); }
public async Task <List <SimulatedRuleEvent> > SimulateAsync(IRuleEntity rule, CancellationToken ct = default) { Guard.NotNull(rule, nameof(rule)); var context = new RuleContext { AppId = rule.AppId, Rule = rule.RuleDef, RuleId = rule.Id, IncludeSkipped = true, IncludeStale = true }; var simulatedEvents = new List <SimulatedRuleEvent>(MaxSimulatedEvents); var fromNow = SystemClock.Instance.GetCurrentInstant().Minus(Duration.FromDays(7)); await foreach (var storedEvent in eventStore.QueryAllReverseAsync($"^([a-zA-Z0-9]+)\\-{rule.AppId.Id}", fromNow, MaxSimulatedEvents, ct)) { var @event = eventDataFormatter.ParseIfKnown(storedEvent); if (@event?.Payload is AppEvent appEvent) { // Also create jobs for rules with failing conditions because we want to show them in th table. await foreach (var result in ruleService.CreateJobsAsync(@event, context, ct)) { var eventName = result.Job?.EventName; if (string.IsNullOrWhiteSpace(eventName)) { eventName = ruleService.GetName(appEvent); } simulatedEvents.Add(new SimulatedRuleEvent { ActionData = result.Job?.ActionData, ActionName = result.Job?.ActionName, EnrichedEvent = result.EnrichedEvent, Error = result.EnrichmentError?.Message, Event = @event.Payload, EventName = eventName, SkipReason = result.SkipReason }); } } } return(simulatedEvents); }
public static RuleDto ToModel(this IRuleEntity entity) { var dto = new RuleDto(); SimpleMapper.Map(entity, dto); SimpleMapper.Map(entity.RuleDef, dto); if (entity.RuleDef.Trigger != null) { dto.Trigger = RuleTriggerDtoFactory.Create(entity.RuleDef.Trigger); } if (entity.RuleDef.Action != null) { dto.Action = RuleActionDtoFactory.Create(entity.RuleDef.Action); } return(dto); }
private async Task EnqueueFromEventsAsync(State currentState, IRuleEntity rule, CancellationToken ct) { var errors = 0; await eventStore.QueryAsync(async storedEvent => { try { var @event = eventDataFormatter.ParseIfKnown(storedEvent); if (@event != null) { var jobs = await ruleService.CreateJobsAsync(rule.RuleDef, rule.Id, @event, false); foreach (var(job, ex) in jobs) { await ruleEventRepository.EnqueueAsync(job, ex); } } } catch (Exception ex) { errors++; if (errors >= MaxErrors) { throw; } log.LogWarning(ex, w => w .WriteProperty("action", "runRule") .WriteProperty("status", "failedPartially")); } finally { currentState.Position = storedEvent.EventPosition; } await state.WriteAsync(); }, $"^([a-z]+)\\-{Key}", currentState.Position, ct); }
public static Task CanUpdate(UpdateRule command, IRuleEntity rule, IAppProvider appProvider) { Guard.NotNull(command, nameof(command)); return(Validate.It(async e => { if (command.Trigger != null) { var errors = await RuleTriggerValidator.ValidateAsync(rule.AppId.Id, command.Trigger, appProvider); errors.Foreach((x, _) => x.AddTo(e)); } if (command.Action != null) { var errors = command.Action.Validate(); errors.Foreach((x, _) => x.AddTo(e)); } })); }
public async Task <List <SimulatedRuleEvent> > SimulateAsync(IRuleEntity rule, CancellationToken ct) { Guard.NotNull(rule, nameof(rule)); var context = GetContext(rule); var result = new List <SimulatedRuleEvent>(MaxSimulatedEvents); var fromNow = SystemClock.Instance.GetCurrentInstant().Minus(Duration.FromDays(7)); await foreach (var storedEvent in eventStore.QueryAllReverseAsync($"^([a-z]+)\\-{rule.AppId.Id}", fromNow, MaxSimulatedEvents, ct)) { var @event = eventDataFormatter.ParseIfKnown(storedEvent); if (@event?.Payload is AppEvent appEvent) { await foreach (var(job, exception, skip) in ruleService.CreateJobsAsync(@event, context, ct)) { var name = job?.EventName; if (string.IsNullOrWhiteSpace(name)) { name = ruleService.GetName(appEvent); } var simulationResult = new SimulatedRuleEvent( name, job?.ActionName, job?.ActionData, exception?.Message, skip); result.Add(simulationResult); } } } return(result); }
public bool CanRunFromSnapshots(IRuleEntity rule) { var context = GetContext(rule); return(CanRunRule(rule) && ruleService.CanCreateSnapshotEvents(context)); }
public bool CanRunRule(IRuleEntity rule) { var context = GetContext(rule); return(context.Rule.IsEnabled && context.Rule.Trigger is not ManualTrigger); }
public bool CanRunFromSnapshots(IRuleEntity rule) { return(CanRunRule(rule) && ruleService.CanCreateSnapshotEvents(rule.RuleDef)); }
private static bool IsFound(IRuleEntity rule) { return(rule.Version > EtagVersion.Empty && !rule.IsDeleted); }
public bool CanRunRule(IRuleEntity rule) { return(rule.RuleDef.IsEnabled && rule.RuleDef.Trigger is not ManualTrigger); }
public Task <List <SimulatedRuleEvent> > SimulateAsync(IRuleEntity rule, CancellationToken ct = default) { return(SimulateAsync(rule.AppId, rule.Id, rule.RuleDef, ct)); }