Browse Source

Fixed issue with subscriber name and remove old hosted service code on ordering.api

pull/491/head
Unai Zorrilla Castro 7 years ago
parent
commit
8f89cebf36
4 changed files with 1 additions and 178 deletions
  1. +0
    -83
      src/Services/Ordering/Ordering.API/Infrastructure/HostedServices/BackgroundService.cs
  2. +0
    -90
      src/Services/Ordering/Ordering.API/Infrastructure/HostedServices/GracePeriodManagerService.cs
  3. +0
    -4
      src/Services/Ordering/Ordering.API/Startup.cs
  4. +1
    -1
      src/Services/Ordering/Ordering.BackgroundTasks/appsettings.json

+ 0
- 83
src/Services/Ordering/Ordering.API/Infrastructure/HostedServices/BackgroundService.cs View File

@ -1,83 +0,0 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
namespace Ordering.API.Infrastructure.HostedServices
{
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
/// <summary>
/// Base class for implementing a long running <see cref="IHostedService"/>.
/// IMPORTANT: This base class is implemented in .NET Core 2.1 - Since this microservice is still in .NET Core 2.0, we're using the class within the project
/// When .NET Core 2.1 is released, this class should be removed and you should use the use implemented by the framework
/// https://github.com/aspnet/Hosting/blob/712c992ca827576c05923e6a134ca0bec87af4df/src/Microsoft.Extensions.Hosting.Abstractions/BackgroundService.cs
///
/// </summary>
//public abstract class BackgroundService : IHostedService, IDisposable
//{
// private Task _executingTask;
// private readonly CancellationTokenSource _stoppingCts = new CancellationTokenSource();
// /// <summary>
// /// This method is called when the <see cref="IHostedService"/> starts. The implementation should return a task that represents
// /// the lifetime of the long running operation(s) being performed.
// /// </summary>
// /// <param name="stoppingToken">Triggered when <see cref="IHostedService.StopAsync(CancellationToken)"/> is called.</param>
// /// <returns>A <see cref="Task"/> that represents the long running operations.</returns>
// protected abstract Task ExecuteAsync(CancellationToken stoppingToken);
// /// <summary>
// /// Triggered when the application host is ready to start the service.
// /// </summary>
// /// <param name="cancellationToken">Indicates that the start process has been aborted.</param>
// public virtual Task StartAsync(CancellationToken cancellationToken)
// {
// // Store the task we're executing
// _executingTask = ExecuteAsync(_stoppingCts.Token);
// // If the task is completed then return it, this will bubble cancellation and failure to the caller
// if (_executingTask.IsCompleted)
// {
// return _executingTask;
// }
// // Otherwise it's running
// return Task.CompletedTask;
// }
// /// <summary>
// /// Triggered when the application host is performing a graceful shutdown.
// /// </summary>
// /// <param name="cancellationToken">Indicates that the shutdown process should no longer be graceful.</param>
// public virtual async Task StopAsync(CancellationToken cancellationToken)
// {
// // Stop called without start
// if (_executingTask == null)
// {
// return;
// }
// try
// {
// // Signal cancellation to the executing method
// _stoppingCts.Cancel();
// }
// finally
// {
// // Wait until the task completes or the stop token triggers
// await Task.WhenAny(_executingTask, Task.Delay(Timeout.Infinite, cancellationToken));
// }
// }
// public virtual void Dispose()
// {
// _stoppingCts.Cancel();
// }
//}
}

+ 0
- 90
src/Services/Ordering/Ordering.API/Infrastructure/HostedServices/GracePeriodManagerService.cs View File

@ -1,90 +0,0 @@
namespace Ordering.API.Infrastructure.HostedServices
{
using Dapper;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
using Microsoft.eShopOnContainers.Services.Ordering.API;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Ordering.API.Application.IntegrationEvents.Events;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Threading;
using System.Threading.Tasks;
//public class GracePeriodManagerService : BackgroundService
//{
// private readonly OrderingSettings _settings;
// private readonly ILogger<GracePeriodManagerService> _logger;
// private readonly IEventBus _eventBus;
// public GracePeriodManagerService(IOptions<OrderingSettings> settings,
// IEventBus eventBus,
// ILogger<GracePeriodManagerService> logger)
// {
// _logger = logger ?? throw new ArgumentNullException(nameof(logger));
// _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
// _settings = settings?.Value ?? throw new ArgumentNullException(nameof(settings));
// }
// protected override async Task ExecuteAsync(CancellationToken stoppingToken)
// {
// _logger.LogDebug($"GracePeriod background task is starting.");
// stoppingToken.Register(() => _logger.LogDebug($"#1 GracePeriod background task is stopping."));
// while (!stoppingToken.IsCancellationRequested)
// {
// _logger.LogDebug($"GracePeriod background task is doing background work.");
// CheckConfirmedGracePeriodOrders();
// await Task.Delay(_settings.CheckUpdateTime, stoppingToken);
// continue;
// }
// _logger.LogDebug($"GracePeriod background task is stopping.");
// }
// private void CheckConfirmedGracePeriodOrders()
// {
// _logger.LogDebug($"Checking confirmed grace period orders");
// var orderIds = GetConfirmedGracePeriodOrders();
// _logger.LogDebug($"GracePeriod sent a .");
// foreach (var orderId in orderIds)
// {
// var gracePeriodConfirmedEvent = new GracePeriodConfirmedIntegrationEvent(orderId);
// _eventBus.Publish(gracePeriodConfirmedEvent);
// }
// }
// private IEnumerable<int> GetConfirmedGracePeriodOrders()
// {
// IEnumerable<int> orderIds = new List<int>();
// using (var conn = new SqlConnection(_settings.ConnectionString))
// {
// try
// {
// conn.Open();
// orderIds = conn.Query<int>(
// @"SELECT Id FROM [ordering].[orders]
// WHERE DATEDIFF(minute, [OrderDate], GETDATE()) >= @GracePeriodTime
// AND [OrderStatusId] = 1",
// new { GracePeriodTime = _settings.GracePeriodTime });
// }
// catch (SqlException exception)
// {
// _logger.LogCritical($"FATAL ERROR: Database connections could not be opened: {exception.Message}");
// }
// }
// return orderIds;
// }
//}
}

+ 0
- 4
src/Services/Ordering/Ordering.API/Startup.cs View File

@ -6,7 +6,6 @@
using global::Ordering.API.Application.IntegrationEvents;
using global::Ordering.API.Application.IntegrationEvents.Events;
using global::Ordering.API.Infrastructure.Filters;
using global::Ordering.API.Infrastructure.HostedServices;
using global::Ordering.API.Infrastructure.Middlewares;
using Infrastructure.AutofacModules;
using Infrastructure.Filters;
@ -58,9 +57,6 @@
}).AddControllersAsServices(); //Injecting Controllers themselves thru DI
//For further info see: http://docs.autofac.org/en/latest/integration/aspnetcore.html#controllers-as-services
//// Configure GracePeriodManager Hosted Service
//services.AddSingleton<IHostedService, GracePeriodManagerService>();
services.AddTransient<IOrderingIntegrationEventService, OrderingIntegrationEventService>();
services.AddHealthChecks(checks =>


+ 1
- 1
src/Services/Ordering/Ordering.BackgroundTasks/appsettings.json View File

@ -13,7 +13,7 @@
}
}
},
"SubscriptionClientName": "Ordering",
"SubscriptionClientName": "BackgroundTasks",
"GracePeriodTime": "1",
"CheckUpdateTime": "1000",
"ApplicationInsights": {


Loading…
Cancel
Save