Beispiel #1
0
        private async Task ProcessAsync(State currentState, CancellationToken ct)
        {
            try
            {
                currentReminder = await RegisterOrUpdateReminder("KeepAlive", TimeSpan.Zero, TimeSpan.FromMinutes(2));

                var rules = await appProvider.GetRulesAsync(DomainId.Create(Key));

                var rule = rules.Find(x => x.Id == currentState.RuleId);

                if (rule == null)
                {
                    throw new InvalidOperationException("Cannot find rule.");
                }

                using (localCache.StartContext())
                {
                    if (currentState.FromSnapshots && ruleService.CanCreateSnapshotEvents(rule.RuleDef))
                    {
                        await EnqueueFromSnapshotsAsync(rule);
                    }
                    else
                    {
                        await EnqueueFromEventsAsync(currentState, rule, 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;
                }
            }
        }
        public bool CanRunFromSnapshots(IRuleEntity rule)
        {
            var context = GetContext(rule);

            return(CanRunRule(rule) && ruleService.CanCreateSnapshotEvents(context));
        }
Beispiel #3
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;
                }
            }
        }
 public bool CanRunFromSnapshots(IRuleEntity rule)
 {
     return(CanRunRule(rule) && ruleService.CanCreateSnapshotEvents(rule.RuleDef));
 }