def execute(self, p_request: ExportRequest = None): """ Executes the export operation """ self._prepare_before_execute(p_request) try: self._status = ExportStatus.BUSY log = Log() log.append_text("Starting data export") self.request.dispatcher.export_data_begin() source_db = self.request.dispatcher.get_client_database( self.request.client) package = Exporter._pull(source_db) Exporter._push(package, self.request.target_db) except Exception as error: # pylint: disable=W0703 error_entry = LogEntry(str(error), p_type=MessageType.error) log.append_entry(error_entry) finally: self.request.dispatcher.export_data_end() log.append_text("Data export finished") try: self.request.target_db.insert_log(log) except Exception: # pylint: disable=W0703 pass self._status = ExportStatus.IDLE print("Export complete")
def delete_log_file_before(self, p_client_id: str, p_before: datetime, p_log: Log): """ Deletes log files before the given date """ log_root_path = self.get_root_path(p_client_id) all_log_files = self.get_log_file_list(p_client_id) for log_file in all_log_files: split1 = log_file.split("T") split2 = split1[0].split("-") log_file_date = datetime(year=int(split2[0]), month=int(split2[1]), day=int(split2[2])) if log_file_date < p_before: full_log_file_path = path.join(log_root_path, log_file) p_log.append_text(f"Deleting {full_log_file_path}") remove(full_log_file_path)
def _drive_passenger(self, p_client: Client, p_client_passenger: ClientPassenger): if self.paused or self._status.shutting_down: return log = Log() db = None # pylint: disable=C0103 driver = None try: log.append_text("Dispatching client " + p_client.id + " passenger " + p_client_passenger.name) log.append_text(f"Creating database {self.ticket.database_module}") db = self.get_client_database(p_client.id, log) # pylint: disable=C0103 log.append_text("Checking schema") db.ensure_schema_existence() log.append_text(f"Creating driver {self.ticket.driver_module}") driver = self.get_driver() log.append_text("Creating ticket") ticket = BusTicket(p_client_passenger=p_client_passenger, p_log=log, p_database=db) log.append_text("Driving") driver.drive(ticket) except Exception as drive_error: # pylint: disable=W0703 if log is not None: log.append_entry( LogEntry(p_message=str(drive_error), p_type=MessageType.error)) finally: self._tick_count.reset_tick(p_client.id, p_client_passenger.name) if self.ticket.dispatcher_observer is not None and log is not None: self.ticket.dispatcher_observer.drive_passenger_complete( p_client, p_client_passenger, log) if db is not None: db.insert_log(log) db.delete_old_logs(p_client.log_expiry_date) if driver is not None: driver.queue.delete_completed_passengers( p_client_passenger.name, p_client_passenger.queue_expiry_date)