Created
May 14, 2012 22:43
-
-
Save eric/2697919 to your computer and use it in GitHub Desktop.
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
module Papertrail | |
module Zookeeper | |
module Convenience | |
def assign(key, value, options = {}) | |
set(key, value, options) | |
rescue ZK::Exceptions::NoNode | |
begin | |
create(key, value, options) | |
rescue ZK::Exceptions::NodeExists | |
set(key, value, options) | |
rescue ZK::Exceptions::NoNode | |
parent = File.dirname(key) | |
if parent && parent != '.' && parent != '' && parent != '/' | |
mkdir_p(parent) | |
retry | |
else | |
raise | |
end | |
end | |
end | |
def get_value(key) | |
result, stat = get(key) | |
result | |
rescue ZK::Exceptions::NoNode | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment