Carlo V. Dango
Carlo V. Dango

Reputation: 13902

How to support future feature flags - eg. the site will shut down in 10 min

In the feature flag offerings out there (flagship, launchdarkly, unleashed,...) you can toggle a feature-flag on and off.

There are situations where a toggle will happen in the future. E.g. the site will shut down in xx minutes

How do we best implement such features toggles given that you only have on/off toggles? Use two feature flags? One specifying the site will go down within 10 minutes, and another toggle to actually close the site.

Upvotes: 1

Views: 589

Answers (1)

Mark C Allen
Mark C Allen

Reputation: 56

Most Feature Flag (LaunchDarkly, DevCycle) tools allow you to use numbers as well as booleans (toggles) to evaluate the feature flag. You could use a number as the time the site is going down and use that to evaluate the message to users and then at that time disable the site.

When you didn’t need to have the message you can just disable the Feature Flag so that it doesn’t get evaluated.

I would do something like this:

Create a new Feature Flag called time-of-site-to-go-own and set the value to 1642723544000 (Jan 21, 2022 12:05:44 am GST). Then enable it for all users.

So using the DevCycle React SDK this would look like this:

import { useDVCVariable } from '@devcycle/devcycle-react-sdk'

export default function CountDown() {
  const variableKey = 'time-of-site-to-go-down'
  const defaultValue = 0
  const featureVariable = useDVCVariable(variableKey, defaultValue)

  if (featureVariable == null) {
    return (<></>);
  }
  
  if (featureVariable.value == 0) {
    return (<div>Site is up</div>) 
  }
  
  var currentTime = new Date().getTime()
  if (currentTime > featureVariable.value) {
    return (<div>Site is down</div>)
  }
  return (
    <div>
      The site will shutdown at: { (new Date(featureVariable?.value)).toString() }
    </div>
  )
}

This would then allow your Product Manager to enable the FF and set the time when they want to turn shut the site down.

Upvotes: 2

Related Questions