Class: Overwatch::Snapshot

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/overwatch/collection/models/snapshot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#raw_dataObject

attr_accessor :data



18
19
20
# File 'lib/overwatch/collection/models/snapshot.rb', line 18

def raw_data
  @raw_data
end

Instance Method Details

#dataObject

after :create, :schedule_reaper



26
27
28
29
30
31
32
33
# File 'lib/overwatch/collection/models/snapshot.rb', line 26

def data
  begin
    Hashie::Mash.new(
      Yajl.load($redis.hget("overwatch::snapshot:#{self.id}", "data"))
    )
  rescue
  end
end

#run_checksObject



35
36
37
# File 'lib/overwatch/collection/models/snapshot.rb', line 35

def run_checks
  self.resource.run_checks
end

#schedule_reaperObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/overwatch/collection/models/snapshot.rb', line 39

def schedule_reaper
  if self.created_at.min % 5 != 0
    Resque.enqueue_in(60.minutes, SnapshotReaper, self)
    # Resque.enqueue_in(60.minutes, AttributeReaper, "resource:#{self.resource_id}:#{key}")
  elsif self.created_at.hour != 0 && self.created_at.min != 0
    Resque.enqueue_in(1.day, SnapshotReaper, self)
  else
    Resque.enqueue_in(30.days, SnapshotReaper, self)
  end
end

#to_dotted_hash(source = self.data, target = {}, namespace = nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/overwatch/collection/models/snapshot.rb', line 50

def to_dotted_hash(source=self.data,target = {}, namespace = nil)
  prefix = "#{namespace}." if namespace
  case source
  when Hash
    source.each do |key, value|
      to_dotted_hash(value, target, "#{prefix}#{key}")
    end
  else
    target[namespace] = source
  end
  target
end