Skip to content
This repository has been archived by the owner on Apr 8, 2023. It is now read-only.

Commit

Permalink
Fix for hosting platform not supporting keep alive
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminsampica committed Jul 11, 2022
1 parent 9679433 commit 6ecf5bf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Server/Features/FreeAgents/EndBidding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task Invoke()

if (!players.Any()) return;

_logger.LogInformation($"Ending bidding for {players.Count} players.");
_logger.LogInformation("Ending bidding for {playerCount} players.", players.Count);

foreach (var player in players)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Server/Features/OfferMatching/ExpireOfferMatching.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace DynamoLeagueBlazor.Server.Features.OfferMatching;
public class ExpireOfferMatchingService : IInvocable
{
private readonly ApplicationDbContext _dbContext;
private ILogger<ExpireOfferMatchingService> _logger;
private readonly ILogger<ExpireOfferMatchingService> _logger;

public ExpireOfferMatchingService(ApplicationDbContext dbContext, ILogger<ExpireOfferMatchingService> logger)
{
Expand All @@ -27,15 +27,15 @@ public async Task Invoke()

if (!players.Any()) return;

_logger.LogInformation($"Expiring offer matching for {players.Count} players.");
_logger.LogInformation("Expiring offer matching for {playersCount} players.", players.Count);

foreach (var player in players)
{
if (!player.Bids.Any())
{
_dbContext.Remove(player);

_logger.LogInformation($"Deleted {player.Name} from the league.");
_logger.LogInformation("Deleted {playerName} from the league.", player.Name);
}
else
{
Expand Down
33 changes: 18 additions & 15 deletions src/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();

app.Services.UseScheduler(scheduler =>
{
var centralStandardTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");

scheduler.Schedule<EndBiddingService>()
.DailyAtHour(22)
.Zoned(centralStandardTimeZone)
.RunOnceAtStart();

scheduler.Schedule<ExpireOfferMatchingService>()
.Daily()
.Zoned(centralStandardTimeZone)
.RunOnceAtStart();
}).OnError((ex) =>
{
Log.Logger.Error(ex, "An exception occured when trying to run a scheduled job.");
});
}

app.UseHttpsRedirection();
Expand All @@ -135,21 +153,6 @@
app.MapControllers().RequireAuthorization();
app.MapFallbackToFile("index.html");

app.Services.UseScheduler(scheduler =>
{
var centralStandardTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
scheduler.Schedule<EndBiddingService>()
.DailyAtHour(22)
.Zoned(centralStandardTimeZone);

scheduler.Schedule<ExpireOfferMatchingService>()
.Daily()
.Zoned(centralStandardTimeZone);
}).OnError((ex) =>
{
Log.Logger.Error(ex, "An exception occured when trying to run a scheduled job.");
});

await using (var scope = app.Services.CreateAsyncScope())
{
var applicationDbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
Expand Down

0 comments on commit 6ecf5bf

Please sign in to comment.