Class: PipelineToolkit::MessageGenerator
- Inherits:
-
Object
- Object
- PipelineToolkit::MessageGenerator
- Defined in:
- lib/pipeline_toolkit/message_generator.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ MessageGenerator
constructor
A new instance of MessageGenerator.
- #send_msg(msg) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(options) ⇒ MessageGenerator
Returns a new instance of MessageGenerator.
7 8 9 10 11 |
# File 'lib/pipeline_toolkit/message_generator.rb', line 7 def initialize() @delay = .delay @msg = JSON.parse(.msg) @limit = .limit end |
Instance Method Details
#send_msg(msg) ⇒ Object
29 30 31 32 |
# File 'lib/pipeline_toolkit/message_generator.rb', line 29 def send_msg(msg) puts MessageCoder.encode(@msg) $stdout.flush end |
#start ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pipeline_toolkit/message_generator.rb', line 13 def start Signal.trap('INT') { puts "Stopping"; exit(0) } Signal.trap('TERM') { puts "Stopping"; exit(0) } Signal.trap('PIPE') { raise "Stopping, lost pipe" } @count = 0 loop do @count += 1 break if @limit && @count > @limit self.send_msg(@msg) sleep(@delay) unless @delay.nil? end end |