Project

General

Profile

Bug #3005 ยป sv.rb

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

 
1
#!/bin/env ruby
2
# encoding: UTF-8
3
#
4

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

    
8
# Enable signal HUP
9
trap 'HUP' do
10
 xml_register_hup
11
end
12

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

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

    
29
# Connect from the XML stream
30
def xml_connect
31
  begin
32
    ios = IO.popen(XMLSTREAM,"w+")
33
    ios.sync = true
34
  rescue Exception => e
35
    puts "#{__method__}: #{e.class} - #{e.message} - #{e.backtrace.inspect}"
36
  end
37
  return ios
38
end
39

    
40
# Processes a XML stream
41
def xml_listener
42
  puts "#{__method__}: Processing XML"
43
  full_xml = ''
44
  while line = $ios.gets
45
    full_xml << line
46
    if line =~ /<\/Active>/
47
      puts "#{__method__}: Full XML: #{full_xml}"
48
      # Do some processing based on the "$cfg_data" data...
49
      full_xml = ''
50
    end
51
  end
52
end
53

    
54

    
55
####################################
56
# Main
57

    
58
$cfg_data = cfgfile_load
59
$ios = xml_connect
60
xml_listener
61