def run(self): while True: try: printRequest = self.get_print_request() except NotFoundException: logging.info("No print request to print. Waiting...") sleep(NODE['QUERY_TIME']) continue except UnauthorizedException: logging.warning("Node unauthorized. Waiting...") sleep(NODE['QUERY_TIME']) continue with Output.new() as output: try: logging.info("Trying to print the request.") output.printRequest(printRequest) except Exception as e: logging.error("There was an error " "during printing:\n{}".format(e)) self.report_failure(printRequest) continue logging.info("Succesfully printed the request.") self.report_success(printRequest) logging.info("Waiting for next request.") sleep(NODE['QUERY_TIME'])
from node import Node import locale import logging import sys # Set the default locale for dates and times in logs locale.setlocale(locale.LC_ALL, '') FORMAT = '%(asctime)s - %(levelname)s - [%(module)s.%(funcName)s] %(message)s' logging.basicConfig( level=logging.DEBUG, format=FORMAT, datefmt='%c' ) if __name__ == '__main__': # Test if the output is valid with Output.new() as output: output.test() # Start the Node try: node = Node() node.run() except KeyboardInterrupt: logging.info("Node successfully terminated.") sys.exit(0)