lib/heirloom/catalog.rb in heirloom-0.11.0 vs lib/heirloom/catalog.rb in heirloom-0.11.1
- old
+ new
@@ -11,10 +11,35 @@
def initialize(args)
@config = args[:config]
@name = args[:name]
end
+ def cleanup(opts = {})
+ opts[:num_to_keep] ||= 100
+ opts[:remove_preserved] ||= false
+
+ num_cleaned = 0
+
+ q = "select * from `#{domain}` where built_at > '2000-01-01T00:00:00.000Z' order by built_at desc"
+
+ sdb.select(q, :offset => opts[:num_to_keep]) do |key, item|
+ unless opts[:remove_preserved]
+ next if preserved?(item)
+ end
+
+ archive = Archive.new :config => @config, :name => @name, :id => key
+ archive.destroy
+ num_cleaned += 1
+ end
+
+ if num_cleaned == 0
+ Heirloom.log.info "No archives to delete."
+ else
+ Heirloom.log.info "#{num_cleaned} archive#{'s' unless num_cleaned == 1} deleted."
+ end
+ end
+
def create_catalog_domain
setup.create_catalog_domain
end
def catalog_domain_exists?
@@ -45,10 +70,18 @@
list.all
end
private
+ def preserved?(item)
+ item['preserve'] && item['preserve'].include?('true')
+ end
+
+ def sdb
+ @sdb ||= Heirloom::AWS::SimpleDB.new :config => @config
+ end
+
def add
@add ||= Catalog::Add.new :config => @config,
:name => @name
end
@@ -70,9 +103,13 @@
:name => @name
end
def verify
@verify ||= Catalog::Verify.new :config => @config
+ end
+
+ def domain
+ "heirloom_#{@name}"
end
end
end