public async Task StartAsync() { _startTime.Start(); long pagingTokenLong = await GetCurrentCursorFromDatabase("operation"); string pagingToken = pagingTokenLong.ToString(); _logger.LogDebug($"Starting page token is {pagingToken}"); _operationsRequestBuilder = _server.Operations.Cursor(pagingToken).Limit(200); _eventSource = _operationsRequestBuilder.Stream((sender, response) => { _operationsToHandleQueue.Enqueue(response); if (_sendQueueInfoMessageTime == null || DateTime.Now >= _sendQueueInfoMessageTime) { _sendQueueInfoMessageTime = DateTime.Now.AddMinutes(1); _logger.LogInformation($"Total operations parsed {_totalRequest}"); _logger.LogInformation($"Currently queued operations {_operationsToHandleQueue.Count}"); _logger.LogInformation($"Current paging token '{response.PagingToken}"); var rpm = _startTime.Elapsed.Minutes > 0 ? $"{_totalRequest / (int)_startTime.Elapsed.TotalMinutes} request handled per minute ({(int)_startTime.Elapsed.TotalMinutes}m)" : ""; if (!string.IsNullOrEmpty(rpm)) { _logger.LogInformation($"{rpm}"); } } }); _eventSource.Error += (sender, args) => { _logger.LogError(args.Exception.Message); }; _eventSource.Connect().Wait(); }
public async void StartAsync() { try { // _databaseQueueService.StartAsync(); await _stellarService.StartAsync(); _logger.LogInformation("Startup service has completed"); } catch (Exception e) { _logger.LogError(e.Message, e); } }
public StellarService(IConfigurationRoot config, HttpClient httpClient, StatsManager statsManager) { _statsManager = statsManager; _config = config; _queueNotifier1 = new AutoResetEvent(false); _httpClient = httpClient; _logger = DicordLogFactory.GetLogger <StellarService>(GlobalVariables.DiscordId, GlobalVariables.DiscordToken); _operationsToHandleQueue = new ConcurrentQueue <OperationResponse>(); ServicePointManager.DefaultConnectionLimit = 100; _logger.LogInformation($"Stellar service is using endpoint {_config["StellarService:HorizonHostname"]}"); _server = new Server(_config["StellarService:HorizonHostname"]); Network.UsePublicNetwork(); _startTime = new Stopwatch(); var queueThread = new Task(HandleResponseQueue, TaskCreationOptions.LongRunning); queueThread.Start(); _timer = new System.Timers.Timer(50); _timer.Elapsed += Timer_tick; _timer.Enabled = true; _timer.Start(); }