Class: PipelineToolkit::MessageGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/pipeline_toolkit/message_generator.rb

Instance Method Summary collapse

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(options)
  @delay = options.delay
  @msg = JSON.parse(options.msg)    
  @limit = options.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

#startObject



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