forked from braintree/curator
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make resettable riak a first class data store.
- Loading branch information
Showing
10 changed files
with
88 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Curator::ResettableRiak | ||
class Configuration < Curator::Riak::Configuration | ||
def data_store | ||
Curator::ResettableRiak::DataStore | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'active_support/core_ext/kernel/reporting' | ||
|
||
module Curator | ||
module ResettableRiak | ||
class DataStore < Riak::DataStore | ||
def self.bucket_prefix | ||
job = "#{ENV['JOB_NAME'].gsub(/[^[:alnum:]]/, '_')}" if ENV['JOB_NAME'].present? | ||
[Curator.config.bucket_prefix, job, Curator.config.environment].compact.join(':') | ||
end | ||
|
||
def self.exclude_from_reset | ||
@exclude_from_reset = true | ||
yield | ||
@exclude_from_reset = false | ||
end | ||
|
||
def self.remove_all_keys | ||
silence_warnings do | ||
buckets = client.buckets.select { |bucket| bucket.name.start_with?(DataStore.bucket_prefix) } | ||
buckets.each do |bucket| | ||
bucket.keys do |keys| | ||
keys.each { |key| bucket.delete(key) } | ||
end | ||
end | ||
end | ||
end | ||
|
||
def self.reset! | ||
@bucket_names ||= {} | ||
deletable_buckets = @bucket_names.each do |bucket_name, keys| | ||
bucket = _bucket(bucket_name) | ||
keys.each {|key| bucket.delete(key)} | ||
end | ||
@bucket_names = {} | ||
end | ||
|
||
def self.save(options) | ||
result = super | ||
|
||
unless @exclude_from_reset | ||
@bucket_names ||= {} | ||
@bucket_names[options[:collection_name]] ||= [] | ||
@bucket_names[options[:collection_name]] << result.key | ||
end | ||
|
||
result | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters