♻️ Refactored presence update logic

This commit is contained in:
2025-11-04 22:13:19 +08:00
parent f271681b5d
commit 58e79655e8
8 changed files with 223 additions and 42 deletions

View File

@@ -84,14 +84,38 @@ public static class ScheduledJobsConfiguration
.WithIdentity("SocialCreditValidationTrigger")
.WithCronSchedule("0 0 0 * * ?"));
var spotifyPresenceUpdateJob = new JobKey("SpotifyPresenceUpdate");
q.AddJob<SpotifyPresenceUpdateJob>(opts => opts.WithIdentity(spotifyPresenceUpdateJob));
// Presence update jobs for different user stages
var activePresenceUpdateJob = new JobKey("ActivePresenceUpdate");
q.AddJob<PresenceUpdateJob>(opts => opts.WithIdentity(activePresenceUpdateJob));
q.AddTrigger(opts => opts
.ForJob(spotifyPresenceUpdateJob)
.WithIdentity("SpotifyPresenceUpdateTrigger")
.ForJob(activePresenceUpdateJob)
.WithIdentity("ActivePresenceUpdateTrigger")
.WithSimpleSchedule(o => o
.WithIntervalInMinutes(2)
.WithIntervalInMinutes(1)
.RepeatForever())
.UsingJobData("stage", nameof(PresenceUpdateStage.Active))
);
var maybePresenceUpdateJob = new JobKey("MaybePresenceUpdate");
q.AddJob<PresenceUpdateJob>(opts => opts.WithIdentity(maybePresenceUpdateJob));
q.AddTrigger(opts => opts
.ForJob(maybePresenceUpdateJob)
.WithIdentity("MaybePresenceUpdateTrigger")
.WithSimpleSchedule(o => o
.WithIntervalInMinutes(3)
.RepeatForever())
.UsingJobData("stage", nameof(PresenceUpdateStage.Maybe))
);
var coldPresenceUpdateJob = new JobKey("ColdPresenceUpdate");
q.AddJob<PresenceUpdateJob>(opts => opts.WithIdentity(coldPresenceUpdateJob));
q.AddTrigger(opts => opts
.ForJob(coldPresenceUpdateJob)
.WithIdentity("ColdPresenceUpdateTrigger")
.WithSimpleSchedule(o => o
.WithIntervalInMinutes(10)
.RepeatForever())
.UsingJobData("stage", nameof(PresenceUpdateStage.Cold))
);
});
services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);

View File

@@ -10,12 +10,13 @@ using NodaTime;
using NodaTime.Serialization.SystemTextJson;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.RateLimiting;
using DysonNetwork.Pass.Account.Presences;
using DysonNetwork.Pass.Auth.OidcProvider.Options;
using DysonNetwork.Pass.Auth.OidcProvider.Services;
using DysonNetwork.Pass.Credit;
using DysonNetwork.Pass.Handlers;
using DysonNetwork.Pass.Leveling;
using DysonNetwork.Pass.Lotteries;
using DysonNetwork.Pass.Mailer;
using DysonNetwork.Pass.Realm;
using DysonNetwork.Pass.Safety;
@@ -144,7 +145,6 @@ public static class ServiceCollectionExtensions
services.AddScoped<ActionLogService>();
services.AddScoped<RelationshipService>();
services.AddScoped<MagicSpellService>();
services.AddScoped<DysonNetwork.Pass.Account.Presences.SpotifyPresenceService>();
services.AddScoped<AuthService>();
services.AddScoped<TokenAuthService>();
services.AddScoped<AccountUsernameService>();
@@ -156,7 +156,10 @@ public static class ServiceCollectionExtensions
services.AddScoped<SocialCreditService>();
services.AddScoped<ExperienceService>();
services.AddScoped<RealmService>();
services.AddScoped<Lotteries.LotteryService>();
services.AddScoped<LotteryService>();
services.AddScoped<SpotifyPresenceService>();
services.AddScoped<IPresenceService, SpotifyPresenceService>();
services.Configure<OidcProviderOptions>(configuration.GetSection("OidcProvider"));
services.AddScoped<OidcProviderService>();