Class: DynamoAutoscale::Poller
- Inherits:
-
Object
- Object
- DynamoAutoscale::Poller
- Includes:
- Logger
- Defined in:
- lib/dynamo-autoscale/poller.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#filters ⇒ Object
Returns the value of attribute filters.
-
#tables ⇒ Object
Returns the value of attribute tables.
Instance Method Summary collapse
- #dispatch(table, data, &block) ⇒ Object
-
#initialize(opts = {}) ⇒ Poller
constructor
The poller constructor accepts a hash of options.
- #run(&block) ⇒ Object
Methods included from Logger
included, logger, #logger, logger=
Constructor Details
#initialize(opts = {}) ⇒ Poller
The poller constructor accepts a hash of options. The following arguments are valid but optional:
- :tables - An array of the tables you would like to poll.
- :filters - This is primarily for working with local data but there
could maybe be a production use for it. Locally, it is used to modify
each datum before it gets sent to the dispatcher. It helps fake setting
provisioned throughput.
14 15 16 17 |
# File 'lib/dynamo-autoscale/poller.rb', line 14 def initialize opts = {} @tables = opts[:tables] || [] @filters = opts[:filters] || [] end |
Instance Attribute Details
#filters ⇒ Object
Returns the value of attribute filters.
4 5 6 |
# File 'lib/dynamo-autoscale/poller.rb', line 4 def filters @filters end |
#tables ⇒ Object
Returns the value of attribute tables.
4 5 6 |
# File 'lib/dynamo-autoscale/poller.rb', line 4 def tables @tables end |
Instance Method Details
#dispatch(table, data, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dynamo-autoscale/poller.rb', line 27 def dispatch table, data, &block times = data.inject([]) do |memo, (_, timeseries)| memo += timeseries.keys end.sort!.uniq! times.each do |time| datum = { provisioned_writes: data[:provisioned_writes][time], provisioned_reads: data[:provisioned_reads][time], consumed_writes: data[:consumed_writes][time], consumed_reads: data[:consumed_reads][time], } filters.each { |filter| filter.call(table, time, datum) } DynamoAutoscale.dispatcher.dispatch(table, time, datum, &block) end end |
#run(&block) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/dynamo-autoscale/poller.rb', line 19 def run &block poll(tables) do |table_name, data| logger.debug "[poller] Got data: #{data}" dispatch(DynamoAutoscale.tables[table_name], data, &block) end end |