Sha256: 308585e41f49f89753e497f2306acc3f8d8b4aeec2305144590b014dfea78c28

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

#!/usr/bin/env ruby
# encoding: utf-8

require 'eventmachine'

__DIR__ = File.dirname(__FILE__)
$LOAD_PATH << File.expand_path('../lib', __DIR__)
require 'tengine/event'

if ARGV.empty? || ARGV.include?("-h") || ARGV.include?("--help")
  puts "#{__FILE__} <event_type_name> [opt1:foo]..."
  exit
end

event_type_name = ARGV.shift
options = ARGV.inject({}) do |d, arg|
  key, value = *arg.split(/:/, 2)
  d[key] = value
  d
end

# see https://github.com/eventmachine/eventmachine/blob/master/tests/test_error_handler.rb
EM.error_handler{ |e|
  puts "[error] tengine.fire Error raised during event loop: #{e.class}, #{e.message}\n"
  puts "#{e.backtrace}\n"
  EM.error_handler(nil)
  EM.stop
}

EM.run do
  if interval = options.delete('interval')
    EM.add_periodic_timer(interval.to_i) do
      puts "-" * 100
      options[:keep_connection] = true
      options[:retry_interval] = 3
      Tengine::Event.fire(event_type_name, options)
    end
  else
    EM.next_tick do
      Tengine::Event.fire(event_type_name, options)
    end
  end
end

Signal.trap("TERM") { connection.close { EM.stop } }
Signal.trap("INT")  { connection.close { EM.stop } }

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tengine_event-1.2.2 bin/tengine_fire
tengine_event-1.2.1 bin/tengine_fire
tengine_event-1.2.0 bin/tengine_fire
tengine_event-1.1.0 bin/tengine_fire
tengine_event-0.4.9 bin/tengine_fire
tengine_event-0.4.8 bin/tengine_fire
tengine_event-0.4.7 bin/tengine_fire
tengine_event-0.4.6 bin/tengine_fire