Beispiel #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
                _logger.LogInformation($"API found on {_serviceBaseUrl}");
                var baseUri       = new Uri($"http://{_serviceBaseUrl}:{_serviceBasePort}");
                var serviceClient = new CurrentIpApiClient(baseUri);
                var ipAddress     = await GetPublicIPAsync(stoppingToken).ConfigureAwait(false);

                var report = new Report {
                    CurrentIP   = ipAddress,
                    MachineName = Environment.MachineName,
                    MachineTag  = "dev-win-10"
                };
                _logger.LogInformation($"Going to log ip {report.CurrentIP} for {report.MachineName} (tagged as {report.MachineTag}) to {baseUri}");
                try {
                    var status = await serviceClient.SubmitReportAsync(report, stoppingToken).ConfigureAwait(false);

                    _logger.LogInformation($"Submitted report to {baseUri} with success status {status}");
                }
                catch (Exception e) {
                    _logger.LogError(e, "Failed to publish a report");
                }
                await Task.Delay(TimeSpan.FromSeconds(_timeOut), stoppingToken);
            }
        }
 public HealthEndpointTests()
 {
     _currentIpApiClient = new CurrentIpApiClient(new Uri(_baseUrl));
 }