Class: Nephelae::Runner
- Inherits:
-
Object
- Object
- Nephelae::Runner
- Includes:
- Logging
- Defined in:
- lib/nephelae/runner.rb
Instance Attribute Summary collapse
-
#aws_access_key_id ⇒ Object
Returns the value of attribute aws_access_key_id.
-
#aws_secret_access_key ⇒ Object
Returns the value of attribute aws_secret_access_key.
-
#plugins ⇒ Object
Returns the value of attribute plugins.
-
#region ⇒ Object
Returns the value of attribute region.
Instance Method Summary collapse
-
#initialize(config = {}) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
Methods included from Logging
Constructor Details
#initialize(config = {}) ⇒ Runner
Returns a new instance of Runner.
9 10 11 12 13 14 15 16 |
# File 'lib/nephelae/runner.rb', line 9 def initialize(config = {}) new_conf = config.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} @aws_access_key_id = new_conf[:aws_access_key_id] @aws_secret_access_key = new_conf[:aws_secret_access_key] @region = new_conf[:region] || 'us-east-1' @plugins = new_conf[:plugins] || default_plugins @plugins[:nephelae_process] = {plugin_class: "NephelaeProcess", schedule: "5m"} end |
Instance Attribute Details
#aws_access_key_id ⇒ Object
Returns the value of attribute aws_access_key_id.
7 8 9 |
# File 'lib/nephelae/runner.rb', line 7 def aws_access_key_id @aws_access_key_id end |
#aws_secret_access_key ⇒ Object
Returns the value of attribute aws_secret_access_key.
7 8 9 |
# File 'lib/nephelae/runner.rb', line 7 def aws_secret_access_key @aws_secret_access_key end |
#plugins ⇒ Object
Returns the value of attribute plugins.
7 8 9 |
# File 'lib/nephelae/runner.rb', line 7 def plugins @plugins end |
#region ⇒ Object
Returns the value of attribute region.
7 8 9 |
# File 'lib/nephelae/runner.rb', line 7 def region @region end |
Instance Method Details
#run ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/nephelae/runner.rb', line 18 def run log.warn "starting nephelae" EM.run { cloud = CloudWatch.new({aws_access_key_id: @aws_access_key_id, aws_secret_access_key: @aws_secret_access_key, region: @region}) #make one request to put a cloud watch metric for nephelae being up. hopefully this can make it bork early if anything is wrong cloud.put_metric(NephelaeProcess.new.get_metrics) scheduler = Rufus::Scheduler::EmScheduler.start_new plugins.each do |name, config| schedule = config.delete(:schedule) || '5m' klass_name = config.delete(:plugin_class) klass = Object.const_get('Nephelae').const_get(klass_name) p = klass.new(config) scheduler.every schedule do begin cloud.put_metric(p.get_metrics) rescue StandardError => e log.error("nephelae plugin #{p.class} failed #{e.}") log.error(e.backtrace.join("\n")) end end end } end |