lib/splash/transfers.rb in prometheus-splash-0.8.0 vs lib/splash/transfers.rb in prometheus-splash-0.8.1
- old
+ new
@@ -47,43 +47,48 @@
class TxRecords
include Splash::Backends
+ include Splash::Constants
+
def initialize(name)
@name = name
- @backend = get_backend :transferts_trace
+ @backend = get_backend :transfers_trace
end
def purge(retention)
+ retention = {} if retention.nil?
if retention.include? :hours then
adjusted_datetime = DateTime.now - retention[:hours].to_f / 24
elsif retention.include? :hours then
adjusted_datetime = DateTime.now - retention[:days].to_i
else
- retention = TRANSFER_DEFAULT_RETENTION
+ adjusted_datetime = DateTime.now - DEFAULT_RETENTION
end
data = get_all_records
- data.delete_if { |item,value|
- DateTime.parse(item) <= (adjusted_datetime) and value[:status] != :prepared}
+ data.delete_if { |item|
+ DateTime.parse(item.keys.first) <= (adjusted_datetime)}
@backend.put key: @name, value: data.to_yaml
end
def add_record(record)
data = get_all_records
- data[DateTime.now.to_s] = record
+ data.push({ DateTime.now.to_s => record })
@backend.put key: @name, value: data.to_yaml
end
- def get_all_records
- return (@backend.exist?({key: @name}))? YAML::load(@backend.get({key: @name})) : {}
+ def get_all_records(options={})
+ return (@backend.exist?({key: @name}))? YAML::load(@backend.get({key: @name})) : []
end
def check_prepared
return :never_run_prepare unless @backend.exist?({key: @name})
- return :never_prepare unless YAML::load(@backend.get({key: @name})).select {|item,value|
+ return :never_prepare unless YAML::load(@backend.get({key: @name})).select {|item|
+ record =item.keys.first
+ value=item[record]
value[:status] == :prepared
}.count > 0
return :prepared
end