def batch_poller(service_host, client_id,poll_time,queue_folder): _logger=logging.getLogger('batch_poller') _logger.info('Polling the service for a search batch...') srv=VXVService(service_host, client_id, 0) count,xml_data=srv.get_search_batch() if count>0: try: time.sleep(5) _logger.info('There is a search batch available, saving it to the disk...') file_name=os.path.join(queue_folder, ('search-batch-%s.xml' % int(time.time()))) f=open(file_name,'w') f.write(xml_data) f.close() except: _logger.exception('An error occurred while saving the received search batch...Exiting...') sys.exit(1) else: _logger.info('There is no search batch available. Polling again in %s seconds..',poll_time) time.sleep(poll_time) batch_poller(service_host, client_id,poll_time,queue_folder)
def send_results_to_service(results,file_name,config): try: xml_file_name=os.path.join(config['queuePath'],file_name+'-results.rxml') max_send_retries=config['max_send_results_retries'] logger.info('Saving xml results file before sending it to the server. File:%s ...',xml_file_name) f=open(xml_file_name,'w') f.write(results) f.close() retries=1 srv=VXVService(config['serviceHost'], config['client_id'],config['client_type']) while retries <= max_send_retries: logger.info('Sending results to the server. Attempt # %s..',retries) if srv.send_search_results(results): logger.info('The server received the results correctly...') return True logger.info('Something happened!!...The server didn''t get the results...trying again...') retries=retries+1 return False except: logger.exception('Ouch!..An exception occurred while sending the results back to the server...')
def LoadXmlConfigurationFromService(service_host,client_id,client_type): srv=VXVService(service_host, client_id, client_type) return srv.get_configuration()