♻️ 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);