protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); try { using var channel = GrpcChannel.ForAddress(_config.GetValue <string>("WorkerService:ServerUrl")); var client = new ProductProtoService.ProductProtoServiceClient(channel); _logger.LogInformation("AddProductAsync started.."); var addProductResponse = await client.AddProductAsync(await _factory.Generate()); _logger.LogInformation("AddProduct Response: {product}", addProductResponse.ToString()); } catch (Exception exception) { _logger.LogError(exception.Message); throw exception; } await Task.Delay(_config.GetValue <int>("WorkerService:TaskInterval"), stoppingToken); } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { Console.WriteLine("Waiting for server is running."); Thread.Sleep(3000); while (!stoppingToken.IsCancellationRequested) { _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); using var channel = GrpcChannel.ForAddress(_config.GetValue <string>("WorkerService:ServiceUrl")); var client = new ProductProtoService.ProductProtoServiceClient(channel); _logger.LogInformation("AddProductAsync started..."); ProductModel response = await client.AddProductAsync(await _productFactory.Generate()); _logger.LogInformation("AddProductAsync response: " + response.ToString()); await Task.Delay(_config.GetValue <int>("WorkerService:TaskInterval"), stoppingToken); } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { Thread.Sleep(2000); while (!stoppingToken.IsCancellationRequested) { _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); var interval = _configuration.GetValue <int>("WorkerService:TaskInterval"); var serverUrl = _configuration.GetValue <string>("WorkerService:ServerUrl"); using var channel = GrpcChannel.ForAddress(serverUrl); var client = new ProductProtoService.ProductProtoServiceClient(channel); _logger.LogInformation("AddProductAsync started..."); var addProductResponse = await client.AddProductAsync(await _productFactory.Generate()); _logger.LogInformation("AddProduct Response: {product}", addProductResponse.ToString()); await Task.Delay(interval, stoppingToken); } }