Skip to content

Instantly share code, notes, and snippets.

@eric
Created May 14, 2012 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eric/2697919 to your computer and use it in GitHub Desktop.
Save eric/2697919 to your computer and use it in GitHub Desktop.
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