toggly
  • What is toggly?
  • 🚀Getting started
    • Creating your first project
    • Using our Feature Flag Demo
    • Inviting Your Team
    • API Documentation
  • 🔘Feature Flags
    • Feature Flags in C# / .NET
      • Views
      • Controllers & Actions
      • Dependency Injection
      • Routing
      • IFeatureManagerSnapshot
      • Persistent Flags Across Requests
      • Disabled Action Handling
      • State Change Handlers
      • Custom Context
      • Snapshot Providers
        • RavenDB
        • Entity Framework
      • Debugging Endpoint
      • Serving Front-end Flags
      • Undefined Features In Development
      • Deployments and Version
    • Feature Flags in Vue.js
      • Feature Component
      • Directly Checking a Flag
      • Users and Rollouts
      • Flag Defaults
    • Feature Flags in JavaScript
      • Directly Checking a Flag
      • Definition Refresh
      • Users and Rollouts
      • Flag Defaults
    • Feature Flags in Flutter
      • Feature Widget
      • Directly Checking a Flag
      • Users and Rollouts
      • Flag Defaults
    • Feature Flags in HTML/CSS
  • 📈Metrics
    • Metrics in C# / .NET
      • Feature Usage
      • Business Metrics
      • Performance Metrics
  • 👩‍💻Use Cases
    • For Engineers
      • Develop continuously, turn on when ready
    • For Product Managers
      • Measure Feature Impact
    • For Agile Teams
      • Faster QA Cycles
      • Streamline Your Releases
Powered by GitBook
On this page
  • IFeatureStateService
  • Feature Flags around Hangfire Jobs

Was this helpful?

  1. Feature Flags
  2. Feature Flags in C# / .NET

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.

Due to the nature of what we're controling, only deterministic states are considered valid, so the state change will only trigger for AlwaysOn and off. Any other type of rollout will be considered off.

* Support for additional deterministic states will be added in the future

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");
});

PreviousDisabled Action HandlingNextCustom Context

Last updated 2 years ago

Was this helpful?

🔘