Ejemplo n.º 1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation($"-----------------------------------------------------");
            _logger.LogInformation($"Service : Startup {DateTime.Now}");
            _logger.LogInformation($"-----------------------------------------------------");

            //var thermoLogic = new ThermoDataLogic(this._logger, this._configuration, _checkPointLogger);
            _serviceWorkerConfiguration.GetDataFromRestServiceIntervalSecond ??= 5000;
            ////////////////////////////////////////////////////////////////////
            thermoLogic.Setup(stoppingToken);
            ////////////////////////////////////////////////////////////////////

            while (!stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation($"**************************************************");
                _logger.LogInformation($"Service : Executing job at {DateTime.Now}.");
                _logger.LogInformation($"**************************************************");
                ////////////////////////////////////////////////////////////////////
                await thermoLogic.ExecuteAsync();

                ////////////////////////////////////////////////////////////////////
                ///
                _logger.LogInformation($"**************************************************");
                _logger.LogInformation($"Service : completed {DateTime.Now}.");
                _logger.LogInformation($"**************************************************");
                _logger.LogInformation($"Service : Waiting to run again in {_serviceWorkerConfiguration.GetDataFromRestServiceIntervalSecond.Value} seconds. {DateTime.Now}.");

                await Task.Delay(new TimeSpan(0, 0, _serviceWorkerConfiguration.GetDataFromRestServiceIntervalSecond.Value),
                                 stoppingToken);
            }

            _logger.LogInformation($"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            _logger.LogInformation($"Service stopped or cancelled! {DateTime.Now}.");
            _logger.LogInformation($"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        }
Ejemplo n.º 2
0
    public Task StartAsync(CancellationToken stoppingToken)
    {
        _logger.LogInformation("Timed Hosted Service running.");

        _thermoLogic = new ThermoDataLogic(this._logger, this._configuration, stoppingToken);
        _thermoLogic.Setup();

        _timer = new Timer(GetThermoDataRestService, null, TimeSpan.Zero,
                           TimeSpan.FromSeconds(5));

        return(Task.CompletedTask);
    }