Skip to content

Commit

Permalink
Merge pull request #5 from vrcx-team/dubya/final-cleanup-before-deplo…
Browse files Browse the repository at this point in the history
…yment

Final cleanup before V0 deployment
  • Loading branch information
DubyaDude authored Aug 22, 2024
2 parents fb63901 + 8637b19 commit 3bc0f85
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
24 changes: 24 additions & 0 deletions VRCX-API/Helpers/DateTimeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Diagnostics;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace VRCX_API.Helpers
{
/// <summary>
/// Converter to match GitHubs DateTimeOffset formatting
/// </summary>
public class DateTimeConverter : JsonConverter<DateTimeOffset?>
{
public override DateTimeOffset? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
Debug.Assert(typeToConvert == typeof(DateTimeOffset));
string? str = reader.GetString();
return string.IsNullOrWhiteSpace(str) ? null : DateTimeOffset.Parse(str);
}

public override void Write(Utf8JsonWriter writer, DateTimeOffset? value, JsonSerializerOptions options)
{
writer.WriteStringValue(value?.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ssZ"));
}
}
}
2 changes: 1 addition & 1 deletion VRCX-API/Helpers/IgnoreEmptyStringNullableEnumConverter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;
using System.Text.Json.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace VRCX_API.Helpers
{
Expand Down
3 changes: 1 addition & 2 deletions VRCX-API/Helpers/LoggerHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog;
using Serilog.Events;

namespace VRCX_API.Helpers
Expand Down
1 change: 1 addition & 0 deletions VRCX-API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static void Main(string[] args)
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower;
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.SnakeCaseLower));
options.JsonSerializerOptions.Converters.Add(new IgnoreEmptyStringNullableEnumConverter());
options.JsonSerializerOptions.Converters.Add(new DateTimeConverter());
});
#if DEBUG
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
Expand Down
9 changes: 6 additions & 3 deletions VRCX-API/Services/CachePeriodicService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
{
public class CachePeriodicService : BackgroundService
{
private const int PeriodicTimerInterval = 60;
private const int RefreshInterval = 120;

private readonly ILogger<CachePeriodicService> _logger;
private readonly GithubCacheService _githubCacheService;
private readonly CloudflareService _cloudflareService;
Expand All @@ -21,17 +24,17 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
await _cloudflareService.PurgeCache();
TriggerGC();

using PeriodicTimer timer = new PeriodicTimer(TimeSpan.FromSeconds(60));
using PeriodicTimer timer = new PeriodicTimer(TimeSpan.FromSeconds(PeriodicTimerInterval));
while (!stoppingToken.IsCancellationRequested && await timer.WaitForNextTickAsync(stoppingToken))
{
try
{
if (DateTime.Now - _lastRefresh > TimeSpan.FromSeconds(120))
if (DateTime.Now - _lastRefresh > TimeSpan.FromSeconds(RefreshInterval))
{
var hasChanged = await _githubCacheService.RefreshAsync();
_lastRefresh = DateTime.Now;

if(hasChanged)
if (hasChanged)
{
await _cloudflareService.PurgeCache();
}
Expand Down
4 changes: 0 additions & 4 deletions VRCX-API/Services/GithubCacheService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using GitHub;
using GitHub.Octokit.Client;
using GitHub.Octokit.Client.Authentication;
using VRCX_API.Configs;
using VRCX_API.Helpers;

Expand Down Expand Up @@ -49,7 +46,6 @@ public async Task<bool> RefreshAsync()
hasChanged |= await RefreshReleases();
hasChanged |= await RefreshAdvisories();

// @TODO Impliment a way to see if latest releases changed.
return hasChanged;
}

Expand Down

0 comments on commit 3bc0f85

Please sign in to comment.