def put(self):
     try:
         url_json = request.form['url']
         pool = db_connection_pool.Pooling()
         connection = pool.get_connection()
         url_db = use_db.use_url_db(connection)
         url_db.delete_urls(url_json)
         return {"result": "success"}
     except Exception as e:
         error = {
             "service_name": "receive_service/url_remover",
             "date": datetime.datetime.now().strftime("%y/%m/%d %H:%M"),
             "exception": e
         }
         loger = exception_logger.ExceptionLogger()
         loger.put_exception(error)
Exemplo n.º 2
0
 def run(self):
     while True:
         conf = configuration_manager.ConfigPack()
         try:
             if int(self.loger.check_size()) > 0:
                 # Get connection from db and insert exception in exception collection
                 pool = db_connection_pool.Pooling()
                 exception = self.loger.pop_exception()
                 connection = pool.get_connection()
                 exception_db = use_db.use_exception_db(connection)
                 exception_db.insert_error(exception)
                 print("A exception log to database !")
         except Exception as e:
             print(str(e))
         except KeyboardInterrupt as e:
             print(str(e))
         time.sleep(conf.get_exception_service_check_time())
def fetch_urls_from_service():
    config = configuration_manager.ConfigPack()
    service_url = config.get_service_url()
    service_get_urls = config.get_service_urls()
    pool = db_connection_pool.Pooling()
    connection = pool.get_connection()
    db = use_db.use_url_db(connection)
    try:
        url_json = requests.get(service_url + service_get_urls)
        db.insert_url(url_json.json())
    except Exception as e:
        error = {
            "service_name": "receiver/fetch_urls",
            "date": datetime.datetime.now().strftime("%y/%m/%d %H:%M"),
            "exception": e
        }
        loger = exception_logger.ExceptionLogger()
        loger.put_exception(error)
    return None
Exemplo n.º 4
0
 def run(self):
     while True:
         try:
             self.conf = configuration_manager.ConfigPack()
             self.pool = db_connection_pool.Pooling()
             connection = self.pool.get_connection()
             url_db = use_db.use_url_db(connection)
             self.url_list = url_db.get_urls_as_list()
             result_list = self.__calculate_parallel__()
             result_db = use_db.use_result_db(connection)
             if len(result_list) is not 0:
                 result_db.inser_results_as_list(result_list)
             time.sleep(self.conf.get_update_time())
         except Exception as e:
             error = {
                 "service_name": "app_main_service/main_service",
                 "date": time.strftime("%d/%m/%Y %I:%M"),
                 "exception": str(e)
             }
             logger = exception_logger.ExceptionLogger()
             logger.put_exception(error)
 def run(self):
     # Store last date that app do sync with main service and we send result for after this time
     last_date_file_location = "send_service/last_sync.txt"
     f = open(last_date_file_location, "r")
     last_date = f.read()
     temporary_date = last_date
     while True:
         self.conf = configuration_manager.ConfigPack()
         try:
             service_url = self.conf.get_service_url()
             service_sync_url = self.conf.get_service_sync_url()
             self.pool = db_connection_pool.Pooling()
             connection = self.pool.get_connection()
             result_db = use_db.use_result_db(connection)
             result_list = result_db.get_result_as_list_after(last_date)
             if len(result_list) > 0:
                 status_dic = {}
                 for x in range(0, len(result_list)):
                     if result_list[x]["date"] >= last_date:
                         last_date = result_list[x]["date"]
                     status_dic[x] = result_list[x]
                 result_json = json.dumps(status_dic)
                 data = [('result', '{"res":' + result_json + '}')]
                 requests.put(service_url + service_sync_url, data=data)
                 f = open(last_date_file_location, "w")
                 f.write(last_date)
                 print("sync done !")
         except Exception as e:
             error = {
                 "service_name": "send_service/send_result",
                 "date": time.strftime("%d/%m/%Y %I:%M"),
                 "exception": str(e)
             }
             logger = exception_logger.ExceptionLogger()
             logger.put_exception(error)
             # If there's any problem in syncing then we have the last date and we can start over there
             f = open(last_date_file_location, "w")
             f.write(temporary_date)
         time.sleep(self.conf.get_sync_time())