Exemplo n.º 1
0
def start():
    # Parse command line argument_parsing
    port, processes, db_data, env = ArgumentParsingUtils.parse_arguments()
    # Set up logger
    Logger.set_up()
    # Create Tornado application
    Logger(__name__).info('Setting up application...')
    app = AppCreator.create_app()
    # Start server on given port and with given processes
    ServerCreator.create(app, port).start(processes)
    # Establish database connection for each process
    Mongo.init(**db_data)
    Mongo.create_indexes()
    app.settings['db'] = Mongo.get()
    # Create basic database entries
    ResourceLoader.load_resources(env)
    # Set up rules engine
    SpecialtyResolver.set_up(env)
    PriorityResolver.set_up(env)
    # Start event loop
    Logger(__name__).info(f'Listening on http://localhost:{port}.')
    IOLoop.current().start()
Exemplo n.º 2
0
    def start(cls):
        # Read command line arguments
        context: ApplicationContext = ArgumentParsingUtils.parse_arguments()

        #initiate application logging
        Logger.initiate_logger(context.logger_configs)
        
        #getting logger
        logger = Logger(cls.__name__)
        logger.info('Initializing the application...')
        logger.debug(f'Configurations: {context}')

        settings = {
            'template_path': abspath(join(dirname(__file__), '../../views/templates')),
            'static_path': abspath(join(dirname(__file__), '../../views/static'))
        }
        # Create application by assigning routes and the location of view files
        app = Application(Router.routes(), **settings)
        
        # Server creation
        server = HTTPServer(app)
        server.bind(context.port)
        server.start(context.process)
        
        # Connect to MongoDB server
        Mongo.init(context.db_configs)
        # This is done so that every incoming request has a pointer to the database connection
        app.settings['db'] = Mongo.get()

        # initiating minio client
        MinioClient.init(context.minio_configs)
        # schedule log file uploader in an interval of hours
        scheduler = TornadoScheduler()
        scheduler.add_job(UploadLogsToMinio.upload_files_to_minio, 'interval', hours=context.logger_configs.log_upload_interval)
        scheduler.start()

        logger.info(f'Listining on port {context.port}')
        IOLoop.current().start()