Skip to content

Commit

Permalink
Make it more modular
Browse files Browse the repository at this point in the history
  • Loading branch information
Sella-GH committed Jun 9, 2024
1 parent 101b806 commit 47ff32f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
17 changes: 13 additions & 4 deletions AzzyBot-Next/Services/Modules/AzuraCastFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using AzzyBot.Services.Interfaces;
using AzzyBot.Utilities;
using AzzyBot.Utilities.Encryption;
using AzzyBot.Utilities.Enums;
using AzzyBot.Utilities.Records.AzuraCast;
using DSharpPlus.Entities;
using Microsoft.Extensions.Hosting;
Expand All @@ -29,17 +30,25 @@ public sealed class AzuraCastFileService(IHostApplicationLifetime applicationLif
private readonly CancellationToken _cancellationToken = applicationLifetime.ApplicationStopping;
private readonly JsonSerializerOptions _serializerOptions = new() { WriteIndented = true };

public void StartAzuraCastFileService()
public void StartAzuraCastFileService(AzuraCastChecks check)
{
_logger.AzuraCastFileServiceStart();

if (_cancellationToken.IsCancellationRequested)
return;

Task.Run(async () => await _taskQueue.QueueBackgroundWorkItemAsync(BuildWorkItemAsync));
switch (check)
{
case AzuraCastChecks.CheckForUpdates:
break;

case AzuraCastChecks.CheckForFileChanges:
Task.Run(async () => await _taskQueue.QueueBackgroundWorkItemAsync(CheckForFileChangesAsync));
break;
}
}

private async ValueTask BuildWorkItemAsync(CancellationToken cancellationToken)
private async ValueTask CheckForFileChangesAsync(CancellationToken cancellationToken)
{
_logger.AzuraCastFileServiceWorkItem();

Expand All @@ -66,7 +75,7 @@ private async ValueTask BuildWorkItemAsync(CancellationToken cancellationToken)
}
catch (OperationCanceledException)
{
_logger.OperationCanceled(nameof(BuildWorkItemAsync));
_logger.OperationCanceled(nameof(CheckForFileChangesAsync));
}

return;
Expand Down
3 changes: 2 additions & 1 deletion AzzyBot-Next/Services/TimerServiceHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using AzzyBot.Logging;
using AzzyBot.Services.Modules;
using AzzyBot.Utilities;
using AzzyBot.Utilities.Enums;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -68,7 +69,7 @@ private async void TimerTimeoutAsync(object? o)
_logger.GlobalTimerCheckForAzuraCastFiles();
_lastAzuraCastFileCheck = now;

_azuraCastFileService.StartAzuraCastFileService();
_azuraCastFileService.StartAzuraCastFileService(AzuraCastChecks.CheckForFileChanges);
}
}
catch (Exception ex)
Expand Down
7 changes: 7 additions & 0 deletions AzzyBot-Next/Utilities/Enums/AzuraCastChecks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace AzzyBot.Utilities.Enums;

public enum AzuraCastChecks
{
CheckForFileChanges,
CheckForUpdates
}

0 comments on commit 47ff32f

Please sign in to comment.