rollout-redis 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d7d811416500c11c77ca8c8490d301c0ce266db5dc6e7967e07c25e435be454
4
- data.tar.gz: c8e76ea2823845c3c3ef2d1929e4e1e75d0f19688ac99b5e4a6e903dae3a57ec
3
+ metadata.gz: 3cbcf193e2048b5dfd5e694a7556844e7d7d9c4aa7426b6f0583a589f7fc8b70
4
+ data.tar.gz: 62d2b603c6a59495c6eca0816cdda4a2ba8b6944544e572a80f208af3c821615
5
5
  SHA512:
6
- metadata.gz: e03a813c99336b16cdee142457f04e56a3cb12b8292f95034a583cd79ae12e97b9586db54cb3070d297bf762259acdb3a9026496124a1a6a40dbcf880fd4433d
7
- data.tar.gz: 632ad6cf617ba379149383ad21e1033d5c6c3c12f9f8de58b1c1465d1440e957760f7ac4c15c011886dd9b188c73f2387b16d7cc144f4ece16446183f8dfcc21
6
+ metadata.gz: cae46805987da343fc78d1ec937a8a42c793eb09dce7dd98aeec2f33f0a615500324ba901e4585a34aa7f64a021766021bf8d942197443e0820005881f3151fd
7
+ data.tar.gz: c679e1a883c8ec708325f3a1a628dc125b9df9d0e014c2b67b7f479b700c10264db42abbf14561052dc19ee4b49564a11e9705744db4cbc146f8f17295b45032
data/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
 
8
+ ## [0.3.0] - 2023-10-24
9
+
10
+ ### Added
11
+ - Providing some rake tasks to the consumers of the gem for allowing them to easily manage their feature flags in their applications:
12
+ - `bundle exec rake rollout:on` rake task for activating feature flags
13
+ - `bundle exec rake rollout:off` rake task for deactivating feature flags
14
+ - `bundle exec rake rollout:list` rake task for listing stored feature flags
15
+
16
+ ## [0.2.0] - 2023-10-23
17
+
18
+ ### Added
19
+
20
+ - `#features` method for listing all the feature flags stored in Redis
21
+
8
22
  ## [0.1.0] - 2023-10-23
9
23
 
10
24
  - Initial version
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # rollout-redis 🚀
1
+ # rollout-redis ⛳️
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/rollout-redis.svg)](https://badge.fury.io/rb/rollout-redis)
4
4
 
@@ -14,6 +14,7 @@ Topics covered in this README:
14
14
  - [Gradual activation based on percentages](#gradual-activation-based-on-percentages)
15
15
  - [Caching Feature Flags](#caching-feature-flags)
16
16
  - [Auto-deactivating flags](#auto-deactivating-flags)
17
+ - [Rake tasks](#rake-tasks)
17
18
  - [Migrating from rollout gem](#migrating-from-rollout-gem-🚨)
18
19
  - [Changelog](#changelog)
19
20
  - [Contributing](#contributing)
@@ -67,6 +68,22 @@ If there is an issue, you have the option to disable a feature:
67
68
  @rollout.deactivate('FEATURE_FLAG_NAME')
68
69
  ```
69
70
 
71
+ If you want to list all the stored feature flags, you can use the `features` method:
72
+
73
+ ```ruby
74
+ @rollout.features
75
+ ```
76
+
77
+ The response will be an array of hashes with all the information about the stored feature flags
78
+
79
+ ```ruby
80
+ [
81
+ { name: 'a-feature-flag', percentage: 100, data: { requests: 50, errors: 1 } },
82
+ { name: 'another-feature-flag', percentage: 20, data: { requests: 1, errors: 0 } },
83
+ { name: 'super-feature-flag', percentage: 50, data: { requests: 828, errors: 34 } }
84
+ ]
85
+ ```
86
+
70
87
  ## Advanced features 🦾
71
88
 
72
89
  ### Gradual activation based on percentages
@@ -143,6 +160,39 @@ end
143
160
 
144
161
  When any unexpected error appears during the wrapped code execution, the Rollout gem will take it into account for automatically deactivating the feature flag if the threshold of errors is reached. All the managed or captured errors inside the wrapped code will not be taken into consideration.
145
162
 
163
+ ## Rake tasks
164
+
165
+ In order to have access to the rollout rakes, you have to load manually the task definitions. For doing so load the rollout rake task:
166
+
167
+ ```ruby
168
+ require 'rollout'
169
+
170
+ load 'rollout/tasks/rollout.rake'
171
+ ```
172
+
173
+ ### Usage
174
+
175
+ To activate/deactivate features, execute the following rake tasks:
176
+
177
+ ```shell
178
+ bundle exec rake rollout:on[feature_name]
179
+ bundle exec rake rollout:off[feature_name]
180
+ ```
181
+
182
+ To a gradual activation based on percentages, pass the percentage as the second parameter when executing the `on` task.
183
+
184
+ ```shell
185
+ bundle exec rake rollout:on[feature_name,50]
186
+ ```
187
+
188
+ _NOTE_: In both cases, `feature_name` **must not** include quotes e.g. `bundle exec rake rollout:on['feature_name']`, as the gem will be unable to fetch its activation status if so.
189
+
190
+ For listing all the stored feature flags, do:
191
+
192
+ ```shell
193
+ bundle exec rake rollout:list
194
+ ```
195
+
146
196
  ## Migrating from rollout gem 🚨
147
197
 
148
198
  If you are currently using the unmaintained [rollout](https://github.com/fetlife/rollout) gem, you should consider checking this [migration guide](https://github.com/jcagarcia/rollout-redis/blob/main/MIGRATING_FROM_ROLLOUT_GEM.md) for start using the new `rollout-redis` gem.
@@ -46,6 +46,17 @@ class Rollout
46
46
  def errors
47
47
  @data[:errors] || 0
48
48
  end
49
+
50
+ def to_h
51
+ {
52
+ name: @name,
53
+ percentage: @percentage,
54
+ data: {
55
+ requests: requests,
56
+ errors: errors
57
+ }
58
+ }
59
+ end
49
60
 
50
61
  private
51
62
 
@@ -0,0 +1,63 @@
1
+
2
+ namespace :rollout do
3
+ desc "Activate a feature"
4
+ task :on, [:feature, :percentage] => :environment do |task, args|
5
+ if args.feature
6
+ puts "Activating feature #{args.feature}..."
7
+ if args.percentage
8
+ activated = rollout.activate(args.feature, args.percentage.to_i)
9
+ else
10
+ activated = rollout.activate(args.feature)
11
+ end
12
+
13
+ if activated
14
+ puts "Feature flag #{args.feature} has been activated! :)"
15
+ else
16
+ puts "Feature flag #{args.feature} has NOT been activated! :("
17
+ end
18
+ end
19
+ end
20
+
21
+ desc "Deactivate a feature"
22
+ task :off, [:feature] => :environment do |task, args|
23
+ if args.feature
24
+ puts "Deactivating feature #{args.feature}..."
25
+ deactivated = rollout.deactivate(args.feature)
26
+ if deactivated
27
+ puts "Feature flag #{args.feature} has been deactivated! :)"
28
+ else
29
+ puts "Feature flag #{args.feature} has NOT been deactivated! :("
30
+ end
31
+ end
32
+ end
33
+
34
+ desc "List features"
35
+ task list: :environment do
36
+ features = rollout.features
37
+ puts "This is the list of all the available features:"
38
+ puts ""
39
+ if !features.empty?
40
+ puts features
41
+ else
42
+ puts "- No feature flags stored"
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def rollout
49
+ @rollout ||= Rollout.new(storage)
50
+ end
51
+
52
+ def storage
53
+ begin
54
+ @storage ||= Redis.new(
55
+ host: ENV.fetch('ROLLOUT_REDIS_HOST'),
56
+ port: ENV.fetch('ROLLOUT_REDIS_PORT')
57
+ )
58
+ rescue KeyError => e
59
+ puts "ROLLOUT_REDIS_HOST and ROLLOUT_REDIS_PORT are mandatory env variables to define in order to run rollout rake tasks"
60
+ raise e
61
+ end
62
+ end
63
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Rollout
4
- VERSION = '0.1.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/rollout.rb CHANGED
@@ -78,6 +78,19 @@ class Rollout
78
78
  raise e
79
79
  end
80
80
 
81
+ def features
82
+ keys = @storage.keys("#{key_prefix}:*")
83
+ return [] if keys.empty?
84
+
85
+ keys.map do |key|
86
+ data = @storage.get(key)
87
+ next unless data
88
+
89
+ feature_name = key.gsub("#{key_prefix}:", '')
90
+ Feature.new(feature_name, JSON.parse(data, symbolize_names: true)).to_h
91
+ end
92
+ end
93
+
81
94
  def clean_cache
82
95
  return unless @cache_enabled
83
96
 
@@ -165,6 +178,10 @@ class Rollout
165
178
  end
166
179
 
167
180
  def key(name)
168
- "feature-rollout-redis:#{name}"
181
+ "#{key_prefix}:#{name}"
182
+ end
183
+
184
+ def key_prefix
185
+ "feature-rollout-redis"
169
186
  end
170
187
  end
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'bundler', '>= 2.4'
28
28
  spec.add_development_dependency 'rspec', '~> 3.12'
29
29
  spec.add_development_dependency 'mock_redis', '~> 0.37'
30
+ spec.add_development_dependency 'rake', '~> 13'
30
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollout-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Carlos García
@@ -72,6 +72,20 @@ dependencies:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0.37'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '13'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '13'
75
89
  description: Fast and easy feature flags based on the latest Redis versions.
76
90
  email:
77
91
  - jugade92@gmail.com
@@ -84,6 +98,7 @@ files:
84
98
  - Rakefile
85
99
  - lib/rollout.rb
86
100
  - lib/rollout/feature.rb
101
+ - lib/rollout/tasks/rollout.rake
87
102
  - lib/rollout/version.rb
88
103
  - rollout-redis.gemspec
89
104
  homepage: https://github.com/jcagarcia/rollout-redis