Exemplo n.º 1
0
        public async Task PublishCaseNumbers()
        {
            //this worker is set to run daily at 2pm but it will run immediately each time the container hosting it is restarted
            //wait until 2pm to run as there is no point in spamming the arcgis server until there is a chance the case numbers have been published

            if (DateTime.Now.Hour < 14)
            {
                var timeToWait = (DateTime.Now.Date.AddHours(14) - DateTime.Now);
                Thread.Sleep(timeToWait);
            }

            var eventMessage = new WorkerServiceStartedEvent();
            await _publishEndPoint.Publish(eventMessage);

            int count = 1;

            var baseUrl = "https://services1.arcgis.com/eNO7HHeQ3rUcBllm/arcgis/rest/services/";

            var latestDateUrl = "CovidStatisticsProfileHPSCIreland_DailyDateView/FeatureServer/0/query?f=json&where=1%3D1&outFields=*&returnGeometry=false&outStatistics=%5B%7B%22onStatisticField" +
                                "%22%3A%22Date%22%2C%22outStatisticFieldName%22%3A%22Date_max%22%2C%22statisticType%22%3A%22max%22%7D%5D";

            var casesUrl = "Covid19StatisticsProfileHPSCIrelandView/FeatureServer/0/query?f=json&where=1%3D1&outFields=*&returnGeometry=false&outStatistics=" +
                           "%5B%7B%22onStatisticField%22%3A%22ConfirmedCovidCases%22%2C%22outStatisticFieldName%22%3A%22ConfirmedCovidCases_sum%22%2C%22statisticType%22%3A%22sum%22%7D%5D";

            var client = _clientFactory.CreateClient();

            while (true)
            {
                if (await NewCasesNumbersArePublished(baseUrl + latestDateUrl, client))
                {
                    await CreateCaseNumbersPublishedEvent(baseUrl + casesUrl, client);

                    return;
                }
                else
                {
                    _logger.LogInformation($"PublishCaseNumbers executed {count++} times");
                    Thread.Sleep(GetWaitTime(DateTime.Now));
                }
            }
        }
        public async Task PublishCaseNumbers()
        {
            var eventMessage = new WorkerServiceStartedEvent();
            await _publishEndPoint.Publish(eventMessage);

            int count = 1;
            var caseNumbersPublished = false;
            var baseUrl = "https://api.twitter.com/2/users/2195808223/tweets";

            var client = _clientFactory.CreateClient();

            while (!caseNumbersPublished)
            {
                caseNumbersPublished = await CheckCaseNumbers(baseUrl, client);

                _logger.LogInformation($"PublishCaseNumbers executed {count++} times");

                if (!caseNumbersPublished)
                {
                    Thread.Sleep(GetWaitTime(DateTime.Now));
                }
            }
        }