Example #1
0
        public async Task ExecuteAsync()
        {
            _logger.LogInformation("{service} running at: {time}", nameof(EntryPointService), DateTimeOffset.Now);
            try
            {
                // EF Requires a scope so we are creating one per execution here
                using var scope = _serviceScopeFactoryLocator.CreateScope();
                var repository =
                    scope.ServiceProvider
                    .GetService <IRepository>();

                // read from the queue
                string message = await _queueReceiver.GetMessageFromQueue(_settings.ReceivingQueueName);

                if (String.IsNullOrEmpty(message))
                {
                    return;
                }

                // check 1 URL in the message
                var statusHistory = await _urlStatusChecker.CheckUrlAsync(message, "");

                // record HTTP status / response time / maybe existence of keyword in database
                repository.Add(statusHistory);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"{nameof(EntryPointService)}.{nameof(ExecuteAsync)} threw an exception.");
                // TODO: Decide if you want to re-throw which will crash the worker service
                //throw;
            }
        }
Example #2
0
        public async Task StartAsync(WorkerDto downTimeAppDto, CancellationToken cancellationToken)
        {
            downTimeAppDto.Timer.Elapsed += async(sender, args) =>
            {
                if (!cancellationToken.IsCancellationRequested)
                {
                    var status = await _urlStatusChecker.CheckUrlAsync(downTimeAppDto.Url);

                    if (!status)
                    {
                        await _notificationFactory
                        .Create((NotificationType)downTimeAppDto.NotificationType, downTimeAppDto.Email)
                        .SendAsync();
                    }
                }
            };
            downTimeAppDto.Timer.Start();
            await Task.CompletedTask;
        }