Class: Fusuma::Plugin::Inputs::TimerInput
- Includes:
- Singleton
- Defined in:
- lib/fusuma/plugin/inputs/timer_input.rb
Overview
libinput commands wrapper
Constant Summary collapse
- DEFAULT_INTERVAL =
5
- EPSILON_TIME =
0.02
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
Attributes inherited from Input
Instance Method Summary collapse
- #config_param_types ⇒ Object
-
#initialize(*args, interval: nil) ⇒ TimerInput
constructor
A new instance of TimerInput.
- #io ⇒ Object
- #start(reader, writer) ⇒ Object
- #timer_loop(writer) ⇒ Object
- #wake_early(t) ⇒ Object
Methods inherited from Input
#create_event, #read_from_io, select
Methods inherited from Base
#config_index, #config_params, inherited, plugins, #shutdown
Constructor Details
#initialize(*args, interval: nil) ⇒ TimerInput
Returns a new instance of TimerInput.
20 21 22 23 24 |
# File 'lib/fusuma/plugin/inputs/timer_input.rb', line 20 def initialize(*args, interval: nil) super(*args) @interval = interval || config_params(:interval) || DEFAULT_INTERVAL @early_wake_queue = Queue.new end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
26 27 28 |
# File 'lib/fusuma/plugin/inputs/timer_input.rb', line 26 def interval @interval end |
Instance Method Details
#config_param_types ⇒ Object
14 15 16 17 18 |
# File 'lib/fusuma/plugin/inputs/timer_input.rb', line 14 def config_param_types { interval: [Float] } end |
#io ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/fusuma/plugin/inputs/timer_input.rb', line 28 def io @io ||= begin reader, writer = create_io start(reader, writer) reader end end |
#start(reader, writer) ⇒ Object
37 38 39 40 41 |
# File 'lib/fusuma/plugin/inputs/timer_input.rb', line 37 def start(reader, writer) Thread.new do timer_loop(writer) end end |
#timer_loop(writer) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fusuma/plugin/inputs/timer_input.rb', line 43 def timer_loop(writer) delta_t = @interval next_wake = Time.now + delta_t loop do sleep_time = next_wake - Time.now if sleep_time <= 0 raise Timeout::Error end Timeout.timeout(sleep_time) do next_wake = [@early_wake_queue.deq, next_wake].min end rescue Timeout::Error writer.puts "timer" next_wake = Time.now + delta_t end rescue Errno::EPIPE exit 0 rescue => e MultiLogger.error e end |
#wake_early(t) ⇒ Object
65 66 67 |
# File 'lib/fusuma/plugin/inputs/timer_input.rb', line 65 def wake_early(t) @early_wake_queue.push(t + EPSILON_TIME) end |