Class: EchiDaemon

Inherits:
Daemon
  • Object
show all
Includes:
EchiConverter
Defined in:
lib/main_win32.rb

Instance Method Summary collapse

Methods included from EchiConverter

#archive_file, #connect_database, #convert_binary_file, #dump_binary, #get_ftp_files, #initiate_logger, #insert_dat_data, #log_processed_file, #process_ascii, #process_dat_files, #process_proper_table, #send_email_alert, #set_directory, #strip_specials

Instance Method Details

#service_initObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/main_win32.rb', line 26

def service_init
  #Open the configuration file
  configfile = $workingdir + '/../config/application.yml' 
  $config = YAML::load(File.open(configfile))

  #Load ActiveRecord Models
  if $config["pco_process"] == 'Y'
    require $workingdir + '/database_presence.rb'
  else
    require $workingdir + '/database.rb'
  end

  #Load the configured schema
  schemafile = $workingdir + "/../config/" + $config["echi_schema"]
  @echi_schema = YAML::load(File.open(schemafile))

  #Open the logfile with appropriate output level
  initiate_logger
  @log.info "ECHI-Converter service initializing"
  $init_date = Time.now
  
  #If configured for database insertion, connect to the database
  if $config["export_type"] == 'database' || $config["export_type"] == 'both'
    connect_database
  end
end

#service_mainObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/main_win32.rb', line 53

def service_main
  @log.info "ECHI-Converter service started with these settings:"
  @log.info $config.inspect
  while running?
    if state == RUNNING
      #Process the files
      get_ftp_files
      #Grab filenames from the to_process directory after an FTP fetch, so if the 
      #system fails it may pick up where it left off
      to_process_dir = $workingdir + "/../files/to_process/"

      #Establish where to copy the processed files to
      @processeddirectory = set_directory($workingdir)

      Dir.entries(to_process_dir).each do | file |
        if file.slice(0,3) == 'chr' && File.stat("#{to_process_dir}/#{file}").size == 0
          @log.info "Encountered a zero bye chr file: #{file}"
          FileUtils.mv("#{to_process_dir}/#{file}", @processeddirectory)
        else
          if file.slice(0,3) == 'chr'
            if $config["echi_format"] == 'BINARY'
              record_cnt = convert_binary_file file
            elsif $config["echi_format"] == 'ASCII'
              record_cnt = process_ascii file
            end
            @log.info "Processed file #{file} with #{record_cnt.to_s} records"
          end
        end
      end
      
      if $config["echi_process_dat_files"] == "Y" && $config["pco_process"] == "N"
        process_dat_files
      end
      
      sleep $config["fetch_interval"]

      #Make sure we did not lose our database connection while we slept
      if ActiveRecord::Base.connected? == 'FALSE'
        connect_database
      end
    end
    
    if state == PAUSED
      @log.info "ECHI-Converter service paused"
      sleep $config["fetch_interval"]
    end
  end
end

#service_pauseObject



18
19
20
# File 'lib/main_win32.rb', line 18

def service_pause
  @log.info "ECHI-Converter service paused"
end

#service_resumeObject



22
23
24
# File 'lib/main_win32.rb', line 22

def service_resume
  @log.info "ECHI-Converter service resumed"
end

#service_stopObject



12
13
14
15
16
# File 'lib/main_win32.rb', line 12

def service_stop
  @log.info "ECHI-Converter service stopped"
  @log.close
  exit!
end