Class: XmlConv::Util::PollingManager

Inherits:
Object
  • Object
show all
Defined in:
lib/xmlconv/util/polling_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(system) ⇒ PollingManager

Returns a new instance of PollingManager.



173
174
175
# File 'lib/xmlconv/util/polling_manager.rb', line 173

def initialize(system)
	@system = system
end

Instance Method Details

#load_sources(&block) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/xmlconv/util/polling_manager.rb', line 176

def load_sources(&block)
     unless File.exist?(CONFIG.polling_file)
       SBSM.warn("Could not find #{CONFIG.polling_file}. Skip polling")
       return
     end
	file = File.open(CONFIG.polling_file)
	YAML.load_documents(file) { |mission|
		block.call(mission)
	}
ensure
	file.close if(file)
end

#poll_sourcesObject



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/xmlconv/util/polling_manager.rb', line 188

def poll_sources
     @@showed_content ||= false
	load_sources do |source|
       begin
         SBSM.info "PollingManage has source #{source.inspect}" unless @@showed_content
         source.poll { |transaction|
           @system.execute(transaction)
         }
       rescue Exception => e
         subject = 'XmlConv2 - Polling-Error'
         body = [e.class, e.message,
                 defined?(source.user) ? 'user '+ source.user : nil,
                 defined?(source.host) ? 'host '+ source.host : nil,
                 defined?(source.port) ? 'port '+ source.port.to_s : nil
                 ].compact.concat(e.backtrace).join("\n")
         Util::Mail.notify source.error_recipients, subject, body
       end
     end
     @@showed_content = true
end