State Change Handlers
In situations where we have a long running service or recurring task, we need to be able to stop and start them
IFeatureStateService
IFeatureStateService allows registering Action handlers which will be called when the feature changes state.
Feature Flags around Hangfire Jobs
var featureStateService = app.Services.GetRequiredService<IFeatureStateService>();
featureStateService.WhenFeatureTurnsOn(FeatureFlags.HourlyJob, () =>
{
//start a service or job
RecurringJob.AddOrUpdate<ITestRecurringJob>("Hourly job", s => s.RunAsync(), Cron.Hourly());
});
featureStateService.WhenFeatureTurnsOff(FeatureFlags.HourlyJob, () =>
{
//stop a service or job
RecurringJob.RemoveIfExists("Hourly job");
});
Last updated
Was this helpful?