Exemple #1
0
        public async Task RunAsync(Action?onWatchlistChange = null, CancellationToken cancellationToken = default)
        {
            _logger.Info("Loading stamps to watch");

            // The watchlist is essentially immutable on every run. The reason is that a change to the Watchlist
            // likely triggers a change in the scheduled rules, so we need to regenerate the entire schedule.
            var watchlist = await Watchlist.CreateAsync(_logger, _cslQueryProvider, _configuration.Environments);

            _logger.Info("Creating rules schedule");
            CreateSchedule(watchlist);

            if (onWatchlistChange != null)
            {
                // This rule takes care of updating the watchlist and triggering the action when it has effectively
                // changed. The action will take care of restarting the entire application.
                _scheduler.Add(new LambdaRule(
                                   identifier: "WatchlistUpdate",
                                   concurrencyBucket: "Kusto",
                                   lambda: async(context) =>
                {
                    if (await watchlist.RefreshAsync())
                    {
                        onWatchlistChange?.Invoke();
                    }
                }), TimeSpan.FromMinutes(30));
            }

            _logger.Info("Entering scheduler loop");
            await _scheduler.RunAsync(cancellationToken);
        }
Exemple #2
0
        public async Task RunAsync(OperationContext context, Action?onWatchlistChange = null)
        {
            Tracer.Info(context, "Loading stamps to watch");

            // The watchlist is essentially immutable on every run. The reason is that a change to the Watchlist
            // likely triggers a change in the scheduled rules, so we need to regenerate the entire schedule.
            var watchlist = await Watchlist.CreateAsync(
                _logger,
                _configuration.Environments,
                _environmentResources.ToDictionary(
                    kvp => kvp.Key,
                    kvp => kvp.Value.KustoQueryClient));

            Tracer.Info(context, "Creating rules schedule");
            CreateSchedule(watchlist);

            if (onWatchlistChange != null)
            {
                // This rule takes care of updating the watchlist and triggering the action when it has effectively
                // changed. The action will take care of restarting the entire application.
                _scheduler.Add(new LambdaRule(
                                   identifier: "WatchlistUpdate",
                                   concurrencyBucket: "Kusto",
                                   lambda: async(ruleContext) =>
                {
                    if (await watchlist.RefreshAsync())
                    {
                        onWatchlistChange?.Invoke();
                    }
                }), TimeSpan.FromMinutes(30));
            }

            Tracer.Info(context, "Entering scheduler loop");
            await _scheduler.RunAsync(context.Token);
        }
Exemple #3
0
        public async Task RunAsync(CancellationToken cancellationToken = default)
        {
            var watchlist = await Watchlist.CreateAsync(_logger, _cslQueryProvider);

            CreateSchedule(watchlist);
            await _scheduler.RunAsync(cancellationToken);
        }