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

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.

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.

Related

Managing 2 conferences with Voximplant scenario

I am trying to make conference with Voximplant, and when user makes a call to another user, while the call is still going on, it makes another call to another user making two calls and the callees is added to a video conferencing.
But it seems the caller is billed twice and the scenerio doesnt look optimised. What should i do to bill once and optimize it?
Scenario:
require(Modules.Conference);
var call, conf = null;
VoxEngine.addEventListener(AppEvents.Started, handleConferenceStarted);
function handleConferenceStarted(e) {
// Create 2 conferences right after session to manage audio in the right way
if( conf === null ){
conf = VoxEngine.createConference(); // create conference
}
conf.addEventListener(CallEvents.Connected,function(){
Logger.write('Conference started')
})
}
VoxEngine.addEventListener(AppEvents.CallAlerting, function(e) {
e.call.addEventListener(CallEvents.Connected, handleCallConnected);
let new_call = VoxEngine.callUser(e.destination,e.callerid,e.displayName,{},true)
new_call.addEventListener(CallEvents.Connected,handleCallConnected);
e.call.answer();
});
function handleCallConnected(e) {
Logger.write('caller connected');
conf.add({
call: e.call,
mode: "FORWARD",
direction: "BOTH", scheme: e.scheme
});
}
You need to end the conference when there are no participants. Refer to the following article in our documentation: https://voximplant.com/docs/guides/conferences/howto. You can find the full scenario code there.
Additionally, I recommend to add some handlers for the CallEvents.Disconnected and the CallEvent.Failed events right after
new_call.addEventListener(CallEvents.Connected,handleCallConnected);
because sometimes the callee may be offline or press a reject button. 🙂

Update data when value changes Vue Js

I have quite a complicated situation and i'm not amazing at Vue so I need some help.
I have a Firebase DB that gets an array (clients) and displays it.
const clientsRef = db.ref('clients')
firebase: {
clients: {
source: clientsRef,
//data has been retrieved from firebase
readyCallback: function() {
this.getSiteCount() // Get number of sites associated with client
this.loaded = true // Hide loader bar once this becomes true
}
}
},
On load complete getSiteCount() will get the clients unique ID and compare it against the sites DB and count how many exist. Below code simply loops around each client and then checks how many sites have the client_id of aClient['.key']. Not really important this works and gets the count and adds it to the clients array.
getSiteCount: function() {
this.clients.forEach((server, clientIndex) => {
this.clients[clientIndex].siteCount= 0
serverContactsRef.orderByChild('client_id').equalTo(server['.key']).on('child_added', (clientDetails) => {
this.clients[clientIndex].siteCount= this.clients[clientIndex].siteCount+ 1
})
})
},
Now in my html I have v-for="clients in filterClients" and the computed function...
filterClients: function() {
function compare(a, b) {
if (a.siteCount < b.siteCount) {
return 1
}
if (a.siteCount > b.siteCount) {
return -1
}
return 0
}
return this.clients.sort(compare)
}
I suspect because the getSiteCount() function runs once the clients have been pulled (0.5s delay) from the DB it's initial siteCount value is 0 and filterClients runs before those values get set. I need to delay filterClients() until the getSiteCount() function runs or need it to update automatically when the getSiteCount() function runs.
Can someone help me make sure the initial load of the page displays the clients in order of how many sites it has (siteCount)
It was in fact a Caveat.
Vue cannot detect the following changes to an array:
When you directly set an item with the index, e.g. vm.items[indexOfItem] = newValue
I changed
this.clients[clientIndex].siteCount= 0
to
Vue.set(this.clients[clientIndex], 'contractsNr', 0)
Updates when the data comes in perfectly now.
Thanks Jacob

lucene query filter not working

I am using this filter hook in my Auth0 Delegated Administration Extension.
function(ctx, callback) {
// Get the company from the current user's metadata.
var company = ctx.request.user.app_metadata && ctx.request.user.app_metadata.company;
if (!company || !company.length) {
return callback(new Error('The current user is not part of any company.'));
}
// The GREEN company can see all users.
if (company === 'GREEN') {
return callback();
}
// Return the lucene query.
return callback(null, 'app_metadata.company:"' + company + '"');
}
When user logged in whose company is GREEN can see all users. But when user logged in whose company is RED can't see any users whose company is RED.
I need to make this when user logged in, user should only be able to access users within his company. (except users from GREEN company).
But above code is not giving expected result. What could be the issue?
This might be related to a little warning note on the User Search documentation page
Basically they don't let you search for properties in the app_metadata field anymore. Unfortunately, this change was breaking and unannounced.
We had to make changes to our API so that we keep a copy of the app_metadatas in a separate database and convert lucene syntax to MongoDB queries, so that we can query by a chain of user_id:"<>" OR user_id:"<>" OR ....
One caveat though, you can't pass a query that's longer than 72 user_ids long. This number is so far undocumented and obtained empirically.
Also, you can't rely on Auth0's hooks to add new users to your database, as these don't fire for social logins, only for Username-Password-Authentication connections.
I hope this gave you some explanation as for why it wasn't working as well as a possible solution.
If I were you, I would look for an alternative for Auth0, which is what we are currently doing.
I finally ended up with this solution.
Used search functionality to filter users. I had to change below two files.
fetchUsers function in client\actions\user.js
changed
export function fetchUsers(search = '', reset = false, page = 0)
to
export function fetchUsers(search = '#red.com', reset = false,
page = 0)
AND
onReset function in client\containers\Users\Users.jsx
changed
onReset = () => { this.props.fetchUsers('', true); }
to
onReset = () => { this.props.fetchUsers('#red.com', true); }

Auto loading a web page for a certain (and fixed) number of times

I need to load a web page and refresh it, automatically, each 5 minutes. It should be refreshed 6 times (30 minutes) and no more. In another question I made, I got a link ( Robust auto-refresh web page ) where a reply from member Reboot has a code I think could be changed to be used as I need. Is it possible to change that code in order to re-load the web page, automatically, for a fixed number of times? If so, how to do it?
This uses sessionStorage to save the number of reloads which should work in IE8+ except for Opera Mini. If this is a problem, set cookies instead (but then the client has to accept cookies).
Tweak maxReloads and pollIntervalSecs to your liking.
<script>
var pollIntervalId;
var pollIntervalSecs = 6;
var maxReloads = 3;
var doReload = function(){
var reloads = sessionStorage.getItem("reloads");
if (!reloads) sessionStorage.setItem("reloads", 0);
reloads++;
if(reloads > maxReloads) {
window.clearInterval(pollIntervalId);
} else {
sessionStorage.setItem("reloads", reloads);
document.location.reload(true);
}
}
pollIntervalId = setInterval(doReload, pollIntervalSecs * 1000);
</script>

Update live tile at fixed interval without having the app running

How can I update my app's live tile at a fixed interval, for example half a day, using JavaScript?
Moreover, it has to be able to update even though the app itself is not running (like the weather app for example)
EDIT: I want to update it locally without having to connect to the internet. And please give some example in JavaScript, not C# please!
To be more specific, for example, how can I set the tile to update once per day, showing the current date?
If the content on the tile is going to be the date, scheduled tile updates are a good option (see ScheduledTileNotification and the JavaScript Scheduled notifications sample on MSDN). You can schedule a notification to occur once a day with the date as the content.
If you can stand up a web service, periodic updates would be a good option. Using this approach, a tile will be updated on a fixed interval whether or not the app is running. Alternatively, you could use push, or update the tile using a background task.
MSDN has a good article on choosing the right notification delivery mechanism, and links to related code samples: http://msdn.microsoft.com/en-us/library/windows/apps/hh779721.aspx
You can use a background task on a schedule for an interval for anything greater than 15 mins. The tasks are designed to be run by the OS separate to your application, so will be executed if it is not active or open.
Here is a detailed blog post on getting started with background tasks: http://www.silverlightshow.net/items/Windows-8-metro-make-your-app-alive-with-background-tasks.aspx
Register a Background Task that executes ever 12 hours and Updates your Tile.
var RegisterBackgroundTask = function (taskEntryPoint, taskName, trigger, condition) {
UnregisterTask(taskName);
Windows.ApplicationModel.Background.BackgroundExecutionManager.requestAccessAsync();
var TaskBuilder = new Windows.ApplicationModel.Background.BackgroundTaskBuilder();
TaskBuilder.name = taskName;
TaskBuilder.taskEntryPoint = taskEntryPoint;
TaskBuilder.setTrigger(trigger);
if (condition !== null) {
TaskBuilder.addCondition(condition);
// If the condition changes while the background task is executing then it will be canceled.
TaskBuilder.cancelOnConditionLoss = true;
}
var task = TaskBuilder.register();
// Remove previous completion status from local settings.
var settings = Windows.Storage.ApplicationData.current.localSettings;
settings.values.remove(taskName);
};
var UnregisterBackgroundTask = function (sTaskName) {
var iter = Windows.ApplicationModel.Background.BackgroundTaskRegistration.allTasks.first();
var hascur = iter.hasCurrent;
while (hascur) {
var cur = iter.current.value;
if (cur.name === sTaskName) {
cur.unregister(true);
}
hascur = iter.moveNext();
}
}
Register Task like this:
RegisterTask(
"App_JS\\LiveTileTask.js",
"Task.LiveTileTask",
new Windows.ApplicationModel.Background.TimeTrigger(15, false),
new Windows.ApplicationModel.Background.SystemCondition(Windows.ApplicationModel.Background.SystemConditionType.internetAvailable)); // 15 min are minimum
In a dedicated File "LiveTileTask.js" you write the Code of your Live Tile Updater:
(function () {
"use strict";
importScripts("//Microsoft.Phone.WinJS.2.1/js/base.js");
var backgroundTaskInstance = Windows.UI.WebUI.WebUIBackgroundTaskInstance.current;
var Notifications = Windows.UI.Notifications;
var tileUpdateManager = Notifications.TileUpdateManager.createTileUpdaterForApplication();
tileUpdateManager.clear();
tileUpdateManager.enableNotificationQueue(true);
for (var i = 0; i < 6; i++) {
var tileWideXml = Notifications.TileUpdateManager.getTemplateContent(Notifications.TileTemplateType.tileSquare150x150Text04),
tileAttributes = tileWideXml.getElementsByTagName("text");
tileAttributes[0].appendChild(tileWideXml.createTextNode("My Live Tile Text No. " + i));
var currentTime = new Date(),
dueTime = new Date(currentTime.getTime() + 30),
tileNotification = new Notifications.ScheduledTileNotification(xmlTile, dueTime),
tileUpdater = Notifications.TileUpdateManager.createTileUpdaterForApplication();
tileUpdater.addToSchedule(tileNotification);
}
backgroundTaskInstance.succeeded = true;
close();
})();
Finally do not forget to register the backgroundtask in your appxmanifest. Under "declarations" select "Background Task" and activate "Timer" and set "Start Page" to "App_JS\LiveTileTask.js". This way you should be able to update your Tile.
You use Azure and Push Notifications to send out notifications to all your app users: http://msdn.microsoft.com/en-us/library/windows/apps/hh465460.aspx
I recommend you create an Azure Mobile Service. It's really easy and cheap and means you get all of the advantages of a separate push service (instead of a scheduled tile notification on the device) to send your push notifications but without all the work. You can sign up for a free trial if you'd like and create up to 10 mobile services for free. You just create a mobile services and then create a scheduled script that runs every 12 hours and in the script you write a little bit of server-side JavaScript code that does your push. That's just one of the things the Mobile Services gives you. You also get data, authentication, and more. www.windowsazure.com