class AutoConsul::Cluster::Registry::S3Provider
Constants
- KEY_TIMESTAMP_FORMAT
Public Class Methods
from_key_base(key_base)
click to toggle source
# File lib/auto-consul/providers/s3.rb, line 63 def self.from_key_base key_base stamp, identifier = key_base.split('-', 2) [read_stamp(stamp), identifier] end
get_s3()
click to toggle source
# File lib/auto-consul/providers/s3.rb, line 28 def self.get_s3 AWS::S3.new end
read_stamp(stamp)
click to toggle source
# File lib/auto-consul/providers/s3.rb, line 54 def self.read_stamp stamp t = Time.strptime(stamp, KEY_TIMESTAMP_FORMAT) Time.utc(t.year, t.month, t.day, t.hour, t.min, t.sec, 0) end
to_key_base(time, identifier)
click to toggle source
# File lib/auto-consul/providers/s3.rb, line 59 def self.to_key_base time, identifier "#{write_stamp time}-#{identifier.to_s}" end
write_stamp(time)
click to toggle source
# File lib/auto-consul/providers/s3.rb, line 50 def self.write_stamp time time.dup.utc.strftime KEY_TIMESTAMP_FORMAT end
Public Instance Methods
bucket()
click to toggle source
# File lib/auto-consul/providers/s3.rb, line 36 def bucket @bucket ||= s3.buckets[bucket_name] end
bucket_name()
click to toggle source
# File lib/auto-consul/providers/s3.rb, line 32 def bucket_name uri.host end
deletes!(deletes)
click to toggle source
# File lib/auto-consul/providers/s3.rb, line 104 def deletes! deletes bucket.objects.delete deletes if deletes.size > 0 end
heartbeat!(identity, data, expiry=nil)
click to toggle source
# File lib/auto-consul/providers/s3.rb, line 72 def heartbeat! identity, data, expiry=nil result = bucket.objects[write_key now, identity].write data purge!(expiry) unless expiry.nil? result end
key_prefix()
click to toggle source
# File lib/auto-consul/providers/s3.rb, line 40 def key_prefix uri.path[1..-1] end
members(expiry)
click to toggle source
# File lib/auto-consul/providers/s3.rb, line 85 def members expiry deletes, actives = [], {} # The expiry gives an exclusive boundary, not an inclusive, # so the minimal allowable key must begin one second after the # specified expiry (given a resolution of seconds). min_time = Time.now.utc - expiry + 1 min_key = File.join(key_prefix, min_time.strftime('%Y%m%d%H%M%S-')) bucket.objects.with_prefix(key_prefix).each do |obj| if obj.key < min_key deletes << obj else o = S3Member.new(obj) actives[o.identifier] = o end end deletes! deletes actives.values.sort_by {|m| [m.time, m.identifier]} end
now()
click to toggle source
# File lib/auto-consul/providers/s3.rb, line 44 def now Time.now end
purge!(expiry)
click to toggle source
# File lib/auto-consul/providers/s3.rb, line 78 def purge! expiry min_key = File.join(key_prefix, "#{self.class.write_stamp(Time.now - expiry + 1)}-") bucket.objects.with_prefix(key_prefix).delete_if do |s3obj| s3obj.key < min_key end end
s3()
click to toggle source
# File lib/auto-consul/providers/s3.rb, line 24 def s3 @s3 ||= self.class.get_s3 end
write_key(time, identity)
click to toggle source
# File lib/auto-consul/providers/s3.rb, line 68 def write_key time, identity File.join(key_prefix, self.class.to_key_base(time, identity)) end