Class: FogTracker::CollectionTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/fog_tracker/collection_tracker.rb

Overview

Tracks a single Fog collection in a single account. Each CollectionTracker instance is tightly bound to an AccountTracker.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_type, account_tracker) ⇒ CollectionTracker

Creates an object for tracking a single Fog collection in a single account

Parameters:

  • resource_type (String)

    the Fog collection name for this resource type

  • account_tracker (AccountTracker)

    the AccountTracker for this tracker’s account. Usually the AccountTracker that created this object



14
15
16
17
18
19
20
21
22
# File 'lib/fog_tracker/collection_tracker.rb', line 14

def initialize(resource_type, )
  @type             = resource_type
  @account_tracker  = 
  @account          = .
  @account_name     = .name
  @log              = .log
  @collection       = Array.new
  @log.debug "Created tracker for #{@type} on #{@account_name}."
end

Instance Attribute Details

#collectionObject (readonly)

An Array of Fog::Model objects, all of the same resource type (class)



8
9
10
# File 'lib/fog_tracker/collection_tracker.rb', line 8

def collection
  @collection
end

Instance Method Details

#clean_account_dataHash

Returns a Hash of account information, slighly modified: a :name parameter is added, and the :credentials are removed :preceeding_update_time is also added.

Returns:

  • (Hash)

    a Hash of account information, slighly modified: a :name parameter is added, and the :credentials are removed :preceeding_update_time is also added



44
45
46
47
48
49
50
# File 'lib/fog_tracker/collection_tracker.rb', line 44

def 
  @clean_data ||= @account  # generate this data only once per res
  @clean_data[:name] = @account_name
  @clean_data[:credentials] = Hash.new
  @clean_data[:preceeding_update_time] = @account_tracker.preceeding_update_time
  @clean_data
end

#updateObject

Polls the AccountTracker‘s connection for updated info on all existing instances of this tracker’s resource_type



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog_tracker/collection_tracker.rb', line 26

def update
  new_collection = Array.new
  fog_collection = @account_tracker.connection.send(@type) || Array.new
  @log.info "Fetching #{fog_collection.count} #{@type} on #{@account_name}."
  # Here's where most of the network overhead is actually incurred
  fog_collection.each do |resource|
    @log.debug "Fetching resource: #{resource.class} #{resource.identity}"
    resource._fog_collection_tracker = self
    new_collection << resource
    #@log.debug "Got resource: #{resource.inspect}"
  end
  @log.info "Fetched #{new_collection.count} #{@type} on #{@account_name}."
  @collection = new_collection
end