Class: FogTracker::Tracker
- Inherits:
-
Object
- Object
- FogTracker::Tracker
- Defined in:
- lib/fog_tracker/tracker.rb
Overview
Tracks one or more Fog accounts and exposes a #query on the results
Instance Attribute Summary collapse
-
#accounts ⇒ Object
a Hash of account information (see accounts.example.yml).
Instance Method Summary collapse
-
#all ⇒ Array <Fog::Model>
Returns an Array of all Resources currenty tracked.
-
#initialize(accounts = {}, options = {}) ⇒ Tracker
constructor
Creates an object for tracking multiple Fog accounts.
-
#logger ⇒ Object
Returns this tracker’s logger, for changing logging dynamically.
-
#preceeding_update_time(account_name) ⇒ Time
Returns the time of given account’s most recent successful update.
-
#query(query_string) ⇒ Array <Fog::Model>
(also: #[])
Returns an array of Resources matching the query_string.
-
#running? ⇒ true, false
Returns true or false, depending on whether this tracker is polling.
-
#start ⇒ Object
Starts periodically polling all this tracker’s accounts for all their Fog resource collections.
-
#stop ⇒ Object
Stops polling for all this tracker’s accounts.
-
#types_for_account(account_name) ⇒ Array<String>
Returns an Array of resource types for a given account.
-
#update ⇒ Array <Fog::Model>
Polls all accounts once in the calling thread (synchronously).
Constructor Details
#initialize(accounts = {}, options = {}) ⇒ Tracker
Creates an object for tracking multiple Fog accounts
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fog_tracker/tracker.rb', line 19 def initialize(accounts = {}, = {}) @delay = [:delay] @callback = [:callback] @log = [:logger] || FogTracker.default_logger @error_proc = [:error_callback] @running = false self.accounts= accounts # Create a Hash that maps account names to AccountTrackers create_trackers end |
Instance Attribute Details
#accounts ⇒ Object
a Hash of account information (see accounts.example.yml)
7 8 9 |
# File 'lib/fog_tracker/tracker.rb', line 7 def accounts @accounts end |
Instance Method Details
#all ⇒ Array <Fog::Model>
Returns an Array of all Resources currenty tracked
89 90 91 92 93 |
# File 'lib/fog_tracker/tracker.rb', line 89 def all results = query '*::*::*::*' (results.each {|r| yield r}) if block_given? results end |
#logger ⇒ Object
Returns this tracker’s logger, for changing logging dynamically
103 |
# File 'lib/fog_tracker/tracker.rb', line 103 def logger ; @log end |
#preceeding_update_time(account_name) ⇒ Time
Returns the time of given account’s most recent successful update
98 99 100 |
# File 'lib/fog_tracker/tracker.rb', line 98 def preceeding_update_time(account_name) @trackers[account_name].preceeding_update_time end |
#query(query_string) ⇒ Array <Fog::Model> Also known as: []
Returns an array of Resources matching the query_string. Calls any block passed for each resulting resource.
78 79 80 81 82 83 84 |
# File 'lib/fog_tracker/tracker.rb', line 78 def query(query_string) results = FogTracker::Query::QueryProcessor.new( @trackers, :logger => @log ).execute(query_string) (results.each {|r| yield r}) if block_given? results end |
#running? ⇒ true, false
Returns true or false, depending on whether this tracker is polling
64 |
# File 'lib/fog_tracker/tracker.rb', line 64 def running? ; @running end |
#start ⇒ Object
Starts periodically polling all this tracker’s accounts for all their Fog resource collections
32 33 34 35 36 37 38 39 40 |
# File 'lib/fog_tracker/tracker.rb', line 32 def start if not running? @log.info "Tracking #{@trackers.keys.count} accounts..." @trackers.each_value {|tracker| tracker.start} @running = true else @log.info "Already tracking #{@trackers.keys.count} accounts" end end |
#stop ⇒ Object
Stops polling for all this tracker’s accounts
43 44 45 46 47 48 49 50 51 |
# File 'lib/fog_tracker/tracker.rb', line 43 def stop if running? @log.info "Stopping tracker..." @trackers.each_value {|tracker| tracker.stop} @running = false else @log.info "Tracking already stopped" end end |
#types_for_account(account_name) ⇒ Array<String>
Returns an Array of resource types for a given account
69 70 71 |
# File 'lib/fog_tracker/tracker.rb', line 69 def types_for_account(account_name) @trackers[account_name].tracked_types end |
#update ⇒ Array <Fog::Model>
Polls all accounts once in the calling thread (synchronously)
55 56 57 58 59 60 |
# File 'lib/fog_tracker/tracker.rb', line 55 def update @trackers.each_value {|tracker| tracker.update} results = all (results.each {|r| yield r}) if block_given? results end |