molasses v0.2.1 Molasses
A feature toggle library using redis or SQL (using Ecto) as a backing service. It allows you to roll out to users based on a percentage. Alternatively, you can use Molasses to deploy to a group of users or user ids.
Installation
- Add
molasses
to your list of dependencies inmix.exs
and runmix deps.get
:
def deps do
[{:molasses, "~> 0.2.0"}]
end
- Install related dependencies by including
ExRedis
orEcto
and one of its adapter libraries for Postgres or Mysql.
2A. Redis
For Redis, you will just need to include exredis:
def deps do
[
{:molasses, "~> 0.2.0"},
{:exredis, ">= 0.2.4"}
]
end
2B. SQL using Ecto
For Ecto with Postgres, install ecto
and postgrex
. You will also need to start ecto and postgrex as applications :
def deps do
[
{:molasses, "~> 0.2.0"},
{:ecto, "~> 2.1.1"},
{:postgrex, ">= 0.0.0"}
]
end
def application do
[applications: [:ecto, :postgrex]]
end
Your config will also need to change. You will need to set up an Ecto Repo like you would here. As well as set the Molasses adapter to postgres.
# molasses adapter setting
config :molasses, adapter: "postgres"
Usage
Molasses uses the same interface whether you are using Redis or SQL. Each function takes an Ecto.Repo
or the ExRedis
client as the first argument.
Summary
Functions
Activates a feature for all users
Activates a feature for some users. When the group argument is an integer then it sets the feature active for a percentage of users. When the group argument is a string then it sets a feature active for that specific user or user group. When the group argument is a list then it sets a feature active for that specific list of users or user groups
Dectivates a feature for all users
Returns a struct of the feature in question
Check to see if a feature is active for all users
Check to see if a feature is active for a specific user
Functions
Activates a feature for some users. When the group argument is an integer then it sets the feature active for a percentage of users. When the group argument is a string then it sets a feature active for that specific user or user group. When the group argument is a list then it sets a feature active for that specific list of users or user groups
Examples
# activate a feature for a percentage of users
Molasses.activate(client, "my_feature", 75)
# activate a feature for a subset of integer based userIds
Molasses.activate(client, "my_feature", [2, 4, 5])
# activate a feature for a subset of string based userIds (think a mongoId) or a list of groups
Molasses.activate(client, "my_feature", ["admins", "super admins"])
# activate a feature for only one group of users
Molasses.activate(client, "my_feature", "powerusers")