Class: AWSTracker::Tracker
- Inherits:
-
Object
- Object
- AWSTracker::Tracker
- Defined in:
- lib/aws_tracker/tracker.rb
Overview
Tracks one or more AwsAccounts in an ActiveRecord database
Instance Attribute Summary collapse
-
#accounts ⇒ Object
readonly
Returns the value of attribute accounts.
-
#delay ⇒ Object
How many seconds to wait between status updates.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Tracker
constructor
Creates an object for tracking AWS accounts Tracked info is stored in an ActiveRecord database with config db_config.
- #load_aws_acounts ⇒ Object
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
- #update_status(selected_accounts = accounts) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Tracker
Creates an object for tracking AWS accounts Tracked info is stored in an ActiveRecord database with config db_config
12 13 14 15 16 |
# File 'lib/aws_tracker/tracker.rb', line 12 def initialize(={}) @log = [:logger] || AWSTracker.default_logger @delay = [:delay] || 300 # default delay is 5 minutes load_aws_acounts end |
Instance Attribute Details
#accounts ⇒ Object (readonly)
Returns the value of attribute accounts.
8 9 10 |
# File 'lib/aws_tracker/tracker.rb', line 8 def accounts @accounts end |
#delay ⇒ Object
How many seconds to wait between status updates
7 8 9 |
# File 'lib/aws_tracker/tracker.rb', line 7 def delay @delay end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
8 9 10 |
# File 'lib/aws_tracker/tracker.rb', line 8 def log @log end |
Instance Method Details
#load_aws_acounts ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/aws_tracker/tracker.rb', line 18 def load_aws_acounts @log.debug "Reading AWS accounts from database..." @accounts = AWSAccount.find(:all) if @accounts.empty? @log.warn "No accounts found in database" end @accounts.each {|acc| acc.log = @log } # pass logger to all resources end |
#running? ⇒ Boolean
35 36 37 |
# File 'lib/aws_tracker/tracker.rb', line 35 def running? @timer != nil end |
#start ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/aws_tracker/tracker.rb', line 39 def start if not running? @log.info "Tracking for #{accounts.count} accounts..." @timer = Thread.new do while true do update_status sleep @delay end end else @log.info "Automatic status updates already running" end end |
#stop ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/aws_tracker/tracker.rb', line 53 def stop if running? @log.info "Stopping automatic updates" @timer.kill @timer = nil else @log.info "Automatic updates already stopped" end end |
#update_status(selected_accounts = accounts) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/aws_tracker/tracker.rb', line 27 def update_status(selected_accounts = accounts) selected_accounts.each do |account| @log.info "Updating account #{account.name}..." account.update_status @log.info "Status update complete for account #{account.name}..." end end |