Project

General

Profile

Bug #3005 ยป sv.rb

syepes (Sebastian YEPES), 03/25/2010 06:46 PM

 
#!/bin/env ruby
# encoding: UTF-8
#

require 'oci8'
XMLSTREAM = "/usr/bin/ftp" # This is a custom programe, but the problem can be reproduced with the ftp..

# Enable signal HUP
trap 'HUP' do
xml_register_hup
end

# Reload configuration function kill -HUP pid
def xml_register_hup
puts "#{__method__}: RELOADING CONFIGURATION DATA"
$cfg_data = cfgfile_load
# Some other processing..
end

# Reads configuration from a DB and returns a hash with the config..
def cfgfile_load
puts "#{__method__}: LOADING CONFIGURATION DATA"
dbh = OCI8.new('dummy', 'dummy', 'anyOra_db')
# Do some processing and build a hash..
dbh.logoff
return {'1' => 'one','2' => "two"}
end

# Connect from the XML stream
def xml_connect
begin
ios = IO.popen(XMLSTREAM,"w+")
ios.sync = true
rescue Exception => e
puts "#{__method__}: #{e.class} - #{e.message} - #{e.backtrace.inspect}"
end
return ios
end

# Processes a XML stream
def xml_listener
puts "#{__method__}: Processing XML"
full_xml = ''
while line = $ios.gets
full_xml << line
if line =~ /<\/Active>/
puts "#{__method__}: Full XML: #{full_xml}"
# Do some processing based on the "$cfg_data" data...
full_xml = ''
end
end
end


####################################
# Main

$cfg_data = cfgfile_load
$ios = xml_connect
xml_listener

    (1-1/1)