Class: DynamoAutoscale::Dispatcher
- Inherits:
-
Object
- Object
- DynamoAutoscale::Dispatcher
- Includes:
- Logger
- Defined in:
- lib/dynamo-autoscale/dispatcher.rb
Instance Method Summary collapse
- #dispatch(table, time, datum, &block) ⇒ Object
-
#initialize ⇒ Dispatcher
constructor
A new instance of Dispatcher.
Methods included from Logger
included, logger, #logger, logger=
Constructor Details
#initialize ⇒ Dispatcher
Returns a new instance of Dispatcher.
5 6 7 |
# File 'lib/dynamo-autoscale/dispatcher.rb', line 5 def initialize @last_check = {} end |
Instance Method Details
#dispatch(table, time, datum, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 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 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dynamo-autoscale/dispatcher.rb', line 9 def dispatch table, time, datum, &block DynamoAutoscale.current_table = table logger.debug "#{time}: Dispatching to #{table.name} with data: #{datum}" # If a nil value comes through, we can reasoanbly assume that it should # have been 0. datum[:consumed_writes] = 0 if datum[:consumed_writes].nil? datum[:consumed_reads] = 0 if datum[:consumed_reads].nil? if datum[:provisioned_reads] and (datum[:consumed_reads] > datum[:provisioned_reads]) lost_reads = datum[:consumed_reads] - datum[:provisioned_reads] logger.warn "[dispatcher][reads] Lost units: #{lost_reads} " + "(#{datum[:consumed_reads]} - #{datum[:provisioned_reads]})" end if datum[:provisioned_writes] and (datum[:consumed_writes] > datum[:provisioned_writes]) lost_writes = datum[:consumed_writes] - datum[:provisioned_writes] logger.warn "[dispatcher][writes] Lost units: #{lost_writes} " + "(#{datum[:consumed_writes]} - #{datum[:provisioned_writes]})" end table.tick(time, datum) block.call(table, time, datum) if block if @last_check[table.name].nil? or @last_check[table.name] < time if time > 20.minutes.ago # Too young to vote! if DynamoAutoscale.actioners[table].can_run? logger.debug "[dispatcher] Checking rules..." DynamoAutoscale.rules.test(table) @last_check[table.name] = time else logger.debug "[dispatcher] Skipped rule check, table is not ready " + "to have its throughputs modified." end else logger.debug "[dispatcher] Skipped rule check, data point was from " + "more than 20 minutes ago. Too young to vote!" end else logger.debug "[dispatcher] Skipped rule check, already checked for " + "a later data point." end DynamoAutoscale.current_table = nil end |