Skip to content

Commit

Permalink
Add selectively enabling/disabling workshop jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Thundernerd committed Sep 4, 2024
1 parent a85adf9 commit 6ea8040
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
8 changes: 8 additions & 0 deletions Jobs/JobOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace TNRD.Zeepkist.GTR.Backend.Jobs;

public class JobOptions
{
public const string Key = "Jobs";

public bool EnableWorkshop { get; set; }
}
25 changes: 18 additions & 7 deletions Jobs/JobScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Hangfire;
using Hangfire.Common;
using Hangfire.States;
using Microsoft.Extensions.Options;
using TNRD.Zeepkist.GTR.Backend.Levels.Jobs;
using TNRD.Zeepkist.GTR.Backend.Levels.Points.Jobs;
using TNRD.Zeepkist.GTR.Backend.Levels.Requests.Jobs;
Expand All @@ -21,11 +22,15 @@ public class JobScheduler : IJobScheduler
{
private readonly IBackgroundJobClient _backgroundJobClient;
private readonly IRecurringJobManager _recurringJobManager;
private readonly JobOptions _options;

public JobScheduler(IBackgroundJobClient backgroundJobClient, IRecurringJobManager recurringJobManager)
public JobScheduler(IBackgroundJobClient backgroundJobClient,
IRecurringJobManager recurringJobManager,
IOptions<JobOptions> options)
{
_backgroundJobClient = backgroundJobClient;
_recurringJobManager = recurringJobManager;
_options = options.Value;
}

public void Enqueue<TJob>(params object[] args)
Expand All @@ -39,7 +44,7 @@ public void Enqueue<TJob>(params object[] args)

public void ScheduleRecurringJobs()
{
#if DEBUG
#if !DEBUG
ScheduleRecurringJob<FixWorldRecordsJob>(Cron.Never());
ScheduleRecurringJob<FixPersonalBestsJob>(Cron.Never());
ScheduleRecurringJob<ProcessLevelRequestsJob>(Cron.Never());
Expand All @@ -48,11 +53,17 @@ public void ScheduleRecurringJobs()
ScheduleRecurringJob<CalculateLevelPointsJob>(Cron.Never());
ScheduleRecurringJob<CalculateUserPointsJob>(Cron.Never());
#else
ScheduleRecurringJob<ProcessLevelRequestsJob>(Cron.MinuteInterval(5));
ScheduleRecurringJob<FullWorkshopScanJob>(Cron.Monthly());
ScheduleRecurringJob<PartialWorkshopScanJob>(Cron.Hourly());
ScheduleRecurringJob<CalculateLevelPointsJob>(Cron.Never());
ScheduleRecurringJob<CalculateUserPointsJob>(Cron.Hourly());
if (_options.EnableWorkshop)
{
ScheduleRecurringJob<ProcessLevelRequestsJob>(Cron.MinuteInterval(5));
ScheduleRecurringJob<FullWorkshopScanJob>(Cron.Monthly());
ScheduleRecurringJob<PartialWorkshopScanJob>(Cron.Hourly());
}
else
{
ScheduleRecurringJob<CalculateLevelPointsJob>(Cron.Never());
ScheduleRecurringJob<CalculateUserPointsJob>(Cron.Hourly());
}
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion Levels/Jobs/WorkshopProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace TNRD.Zeepkist.GTR.Backend.Levels.Jobs;

public class WorkshopProcessor
{
private const int MaxConcurrency = 5;
private const int MaxConcurrency = 2;

private readonly ILogger<WorkshopProcessor> _logger;
private readonly IServiceProvider _provider;
Expand Down
1 change: 1 addition & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
builder.Services.Configure<WasabiStorageOptions>(builder.Configuration.GetSection(WasabiStorageOptions.Key));
builder.Services.Configure<WorkshopOptions>(builder.Configuration.GetSection(WorkshopOptions.Key));
builder.Services.Configure<LoggerOptions>(builder.Configuration.GetSection(LoggerOptions.Key));
builder.Services.Configure<JobOptions>(builder.Configuration.GetSection(JobOptions.Key));

builder.Services.AddRefitClient<IPublishedFileServiceApi>(
provider => new RefitSettings()
Expand Down

0 comments on commit 6ea8040

Please sign in to comment.