flux_capacitor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +73 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/flux_capacitor.gemspec +29 -0
- data/lib/flux_capacitor.rb +52 -0
- data/lib/flux_capacitor/version.rb +3 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5bdc364e1a19df5645ef0291b4c8fb231f7a5c91
|
4
|
+
data.tar.gz: 1fd589797273708272ef7db6908eeee460fc5b3c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e33a47111b4fa40fd04b6e28894c89f0a4b5db3e295e21e42369dbe6d34181e822fa9447c1190ccf55c2e628a718ef1957d9b2242738495d8e4cdb79d81ce882
|
7
|
+
data.tar.gz: 3e5be9ef3e76884bb73b8ba2bf6a6399724775899b44ab62b391726cf8f2f75f07d6e9c7929a046187cc71e25b074f45be57dfe08ea2112eb62d9e3b545e88ed
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# FluxCapacitor
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/flux_capacitor`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'flux_capacitor'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install flux_capacitor
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'flux_capacitor'
|
27
|
+
|
28
|
+
pivot = DateTime.parse('2017/08/14 00:00:00-000') # Everything after this date will have the new feature. This is the point in time when your new feature will start to go live
|
29
|
+
oldest = MyModel.first.created_at # If you are using active record finding your oldest item is pretty easy, otherwise if you know the date of your first item, just use that
|
30
|
+
end_point = DateTime.parse('2017/09/14') # At this point the feature should be fully rolled out and it is safe to remove the Flux Capacitor. This dictates how quickly the feature rolls out. If you are concerned about overloading a required service set this to farther in the future to lower load
|
31
|
+
|
32
|
+
FEATURE_1_CAPACITOR = Flux::Capacitor.new(pivot, end_point, oldest)
|
33
|
+
|
34
|
+
def controller_method
|
35
|
+
model = MyModel.find(params[:id])
|
36
|
+
if FEATURE_1_CAPACITOR.travel_to?(model.created_at)
|
37
|
+
use_new_feature
|
38
|
+
else
|
39
|
+
use_old_feature
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
If your feature doesn't map well to something where you have a date for each piece of content you can still use flux capacitor. It can also take strings and distribute them evenly over your rollout period using the murmur3 hashing algorithm.
|
45
|
+
```ruby
|
46
|
+
require 'flux_capacitor'
|
47
|
+
pivot = DateTime.parse('2017/08/14 00:00:00-000') # when do you want to start rolling out the feature
|
48
|
+
end_point = DateTime.parse('2017/09/14') # when do you want the rollout to finish
|
49
|
+
|
50
|
+
# NOTE: We don't need an oldest date when using strings
|
51
|
+
FEATURE_1_CAPACITOR = Flux::Capacitor.new(pivot, end_point)
|
52
|
+
|
53
|
+
def controller_method
|
54
|
+
model = MyModel.find(params[:id])
|
55
|
+
if FEATURE_1_CAPACITOR.travel_to?(model.uuid)
|
56
|
+
use_new_feature
|
57
|
+
else
|
58
|
+
use_old_feature
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
62
|
+
|
63
|
+
One note about using the string hashing method, new content could get the old feature for a while.
|
64
|
+
|
65
|
+
## Development
|
66
|
+
|
67
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
68
|
+
|
69
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
70
|
+
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/raphaeleidus/flux_capacitor.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "flux_capacitor"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "flux_capacitor/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "flux_capacitor"
|
8
|
+
spec.version = Flux::VERSION
|
9
|
+
spec.authors = ["Raphael Eidus"]
|
10
|
+
spec.email = ["raphaeleidus@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Utility for progressively rolling out a feature to existing content}
|
13
|
+
spec.description = %q{When you have some service that might not be able to handle a large transition of historical content, say a dynamic image service.
|
14
|
+
Instead of changing everything at once you can use the flux capacitor to progressively enable the new functionality based on content age.}
|
15
|
+
spec.homepage = "https://github.com/raphaeleidus/flux_capacitor"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "murmurhash3"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'flux_capacitor/version'
|
2
|
+
require 'date'
|
3
|
+
require 'murmurhash3'
|
4
|
+
|
5
|
+
module Flux
|
6
|
+
|
7
|
+
class Capacitor
|
8
|
+
attr_reader :pivot, :pivot_ts, :time_dilation
|
9
|
+
def initialize (start_time, completion_target, oldest_target = Capacitor.oldest_string_time(start_time))
|
10
|
+
@pivot = start_time
|
11
|
+
@pivot_ts = pivot.strftime("%s").to_i
|
12
|
+
time_to_complete = seconds_between(completion_target, pivot)
|
13
|
+
dilation = seconds_between(pivot, oldest_target).to_f / time_to_complete.to_f
|
14
|
+
@time_dilation = dilation
|
15
|
+
end
|
16
|
+
|
17
|
+
def limit
|
18
|
+
diff = seconds_between(DateTime.now, pivot)
|
19
|
+
datetime_minus_seconds(pivot, (diff * time_dilation).to_i)
|
20
|
+
end
|
21
|
+
|
22
|
+
def travel_to?(destination)
|
23
|
+
destination = destination.is_a?(DateTime) ? destination : string_to_time(destination)
|
24
|
+
limit < destination
|
25
|
+
end
|
26
|
+
|
27
|
+
def string_to_time(str)
|
28
|
+
Capacitor.string_to_time(pivot, str)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.string_to_time(pivot, str)
|
32
|
+
timestamp = pivot.strftime("%s").to_i - (MurmurHash3::V32.str_hexdigest(str).to_i(16)/8)
|
33
|
+
DateTime.strptime(timestamp.to_s, "%s")
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.oldest_string_time(pivot)
|
37
|
+
timestamp = pivot.strftime("%s").to_i - ("ffffffff".to_i(16)/8)
|
38
|
+
DateTime.strptime(timestamp.to_s, "%s")
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def seconds_between(date_time_1, date_time_2)
|
44
|
+
date_time_1.strftime("%s").to_i - date_time_2.strftime("%s").to_i
|
45
|
+
end
|
46
|
+
|
47
|
+
def datetime_minus_seconds(datetime, seconds)
|
48
|
+
ts = (datetime.strftime("%s").to_i - seconds).to_s
|
49
|
+
DateTime.strptime(ts, "%s")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flux_capacitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Raphael Eidus
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: murmurhash3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.15'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.15'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: |-
|
70
|
+
When you have some service that might not be able to handle a large transition of historical content, say a dynamic image service.
|
71
|
+
Instead of changing everything at once you can use the flux capacitor to progressively enable the new functionality based on content age.
|
72
|
+
email:
|
73
|
+
- raphaeleidus@gmail.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- flux_capacitor.gemspec
|
87
|
+
- lib/flux_capacitor.rb
|
88
|
+
- lib/flux_capacitor/version.rb
|
89
|
+
homepage: https://github.com/raphaeleidus/flux_capacitor
|
90
|
+
licenses: []
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.5.1
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Utility for progressively rolling out a feature to existing content
|
112
|
+
test_files: []
|