Module: TiltHydrometer::ThrotteledExecution

Included in:
Brewfather
Defined in:
lib/tilt_hydrometer/throttled_execution.rb

Instance Method Summary collapse

Instance Method Details

#execution_allowed?(uuid) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
# File 'lib/tilt_hydrometer/throttled_execution.rb', line 16

def execution_allowed?(uuid)
  return true if timers[uuid].nil?

  # puts @interval.inspect

  timers[uuid] + @interval < Time.now.utc
end

#reset_timer(uuid) ⇒ Object



24
25
26
# File 'lib/tilt_hydrometer/throttled_execution.rb', line 24

def reset_timer(uuid)
  timers[uuid] = Time.now.utc
end

#throtteled_execution(uuid) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/tilt_hydrometer/throttled_execution.rb', line 5

def throtteled_execution(uuid)
  unless execution_allowed?(uuid)
    LOGGER.debug('Execution got throtteled')
    return
  end

  reset_timer(uuid)

  yield
end

#timersObject



28
29
30
# File 'lib/tilt_hydrometer/throttled_execution.rb', line 28

def timers
  @timers ||= {}
end