コード例 #1
0
        public Task StartAsync(CancellationToken stoppingToken)
        {
            logger.LogInformation("{0} service running.", nameof(FasterHostedServiceCommit));
            var state = new FasterHostedServiceCommitState(FasterOps.Instance.Value.CommitAsync, logger, GetLoggingInterval(), PeriodMs);

            timer = new Timer(ExecuteAsync, state, TimeSpan.Zero, TimeSpan.FromMilliseconds(PeriodMs));
            return(Task.CompletedTask);
        }
コード例 #2
0
        private async void ExecuteAsync(object stateInfo)
        {
            FasterHostedServiceCommitState state = stateInfo as FasterHostedServiceCommitState;

            try
            {
                await state.CommitAsync();
            }
            catch (Exception e)
            {
                logger.LogError("Commit failed: {0}", e);
            }

            if (state.InvokationCount > 0 && state.InvokationCount % state.LoggingInterval == 0)
            {
                state.InvokationCount = 0;
                state.Logger.LogInformation("Polling commits every {0} ms", state.PeriodMs);
            }
            else
            {
                state.InvokationCount++;
            }
        }