Example #1
0
        public async Task <IActionResult> Simulate(string app, DomainId id)
        {
            var rule = await appProvider.GetRuleAsync(AppId, id);

            if (rule == null)
            {
                return(NotFound());
            }

            var simulation = await ruleRunnerService.SimulateAsync(rule, HttpContext.RequestAborted);

            var response = SimulatedRuleEventsDto.FromSimulatedRuleEvents(simulation);

            return(Ok(response));
        }
Example #2
0
        private async Task ProcessAsync(State currentState, CancellationToken ct)
        {
            try
            {
                currentReminder = await RegisterOrUpdateReminder("KeepAlive", TimeSpan.Zero, TimeSpan.FromMinutes(2));

                var rule = await appProvider.GetRuleAsync(DomainId.Create(Key), currentState.RuleId !.Value);

                if (rule == null)
                {
                    throw new DomainObjectNotFoundException(currentState.RuleId.ToString() !);
                }

                using (localCache.StartContext())
                {
                    var context = new RuleContext
                    {
                        AppId       = rule.AppId,
                        Rule        = rule.RuleDef,
                        RuleId      = rule.Id,
                        IgnoreStale = true
                    };

                    if (currentState.RunFromSnapshots && ruleService.CanCreateSnapshotEvents(context))
                    {
                        await EnqueueFromSnapshotsAsync(context, ct);
                    }
                    else
                    {
                        await EnqueueFromEventsAsync(currentState, context, ct);
                    }
                }
            }
            catch (OperationCanceledException)
            {
                return;
            }
            catch (Exception ex)
            {
                log.LogError(ex, w => w
                             .WriteProperty("action", "runRule")
                             .WriteProperty("status", "failed")
                             .WriteProperty("ruleId", currentState.RuleId?.ToString()));
            }
            finally
            {
                if (!isStopping)
                {
                    currentState.RuleId   = null;
                    currentState.Position = null;

                    await state.WriteAsync();

                    if (currentReminder != null)
                    {
                        await UnregisterReminder(currentReminder);

                        currentReminder = null;
                    }

                    currentJobToken?.Dispose();
                    currentJobToken = null;
                }
            }
        }