Skip to content

Commit

Permalink
add notify to toggle base
Browse files Browse the repository at this point in the history
  • Loading branch information
budipang committed Aug 28, 2018
1 parent 988bd61 commit 08c973e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/toggleable/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def toggle_key(value, actor)
Toggleable.configuration.storage.set(key, value, namespace: Toggleable.configuration.namespace)
Toggleable::FeatureToggler.instance.toggle_key(key, value, actor: actor)
Toggleable.configuration.logger&.log(key: key, value: value, actor: actor)
notify_changes(key, value) if Toggleable.configuration.notify_endpoint
end

def toggle_active
Expand All @@ -65,6 +66,13 @@ def toggle_active
def read_expired?
@_last_read_at < Time.now.localtime - Toggleable.configuration.expiration_time
end

def notify_changes(toggles, values)
url = "#{Toggleable.configuration.notify_endpoint}/notify_toggle?keys=#{toggles}&values=#{values}"
RestClient::Resource.new(url).get timeout: 2, open_timeout: 1
rescue StandardError
nil
end
end
end
end
2 changes: 2 additions & 0 deletions spec/toggleable/toggleable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class SampleFeature

before(:each) do
allow(Toggleable::FeatureToggler.instance).to receive(:toggle_key).and_return(true)
stub_request(:get, "http://localhost:5858/notify_toggle?keys=sample_feature&values=true").to_return(status: 200, body: 'success')
stub_request(:get, "http://localhost:5858/notify_toggle?keys=sample_feature&values=false").to_return(status: 200, body: 'success')
end

describe 'active? before key exist should create the key also' do
Expand Down

0 comments on commit 08c973e

Please sign in to comment.