Trivial (hello world) Flask app on OML

Hi,


I am trying to run a trivial app, I added some logging too. Neither is successfull: I am getting error 503 from the app and logging does not show new entry. I am attaching the full notebook.

Any ideas?

Thanks!


P.S.: Somehow the upload of ipynb is blocked...


Comments

  • edited November 2020

    I am getting error 503 from the app

    In general a 503 means the app did not start properly. Perhaps an exception is thrown right early in starting up the application.

    and logging does not show new entry.

    You can get log messages from the app by adding the following to your module's create_app function. Note setting the log level to DEBUG should be done for debugging only - change the log level to ERROR after it works.

    def create_app(..., server=None):    
        import logging, traceback, sys
        from omegaml.store.logging import OmegaLoggingHandler
        logger = logging.getLogger(__name__)
        handler = OmegaLoggingHandler.setup(level='DEBUG', logger=logger)
        sys.excepthook = lambda t, v, tb: [logger.error(l) for l in traceback.format_tb(tb)]
    

    Then in your Jupyter or other omega|ml console

    $ om runtime log -f
    2020-11-17 13:28:50,134 - dashboard.app - INFO - Dash is running on http://127.0.0.1:8050/
    ...
    

    Note it doesn't matter whether the app is running locally or on apphub as all log routing is done through om.datasets. The module that does the routing is OmegaLoggingHandler . All the other parts are standard Python logging, see https://docs.python.org/3.2/howto/logging.html#logging-advanced-tutorial.

    There are a few other interesting loggers that you could attach to as follows (this can provide a lot of irrelevant details, use with caution). For details on how Flask logging works, see https://flask.palletsprojects.com/en/1.1.x/logging/

    for name in ('werkzeug', 'flask.app', 'root'):
        logger = logging.getLogger(name) 
        logger.setLevel('DEBUG')
        logger.addHandler(handler) 
    

    It can help to test the application by running it locally. You can do this by adding the following snippet to your module's __main__.py :

    from mymodule import create_app
    
    if __name__ == '__main__':
        # essentially as apphub does 
        server = Flask(__name__)
        create_app(server=server, uri='/apps/username/mymodule')
        server.run()
    

    Then on your console:

    $ python -m mymodule
    Dash is running on http://127.0.0.1:8050/
    ...
    

    Open http://localhost:8050/apps/username/mymodule to see the app's page. Note the URI is created by apphub as the default name.

  • Thanks!

    I am attaching the working app for reference.

    It includes logging and the flask-restx usage.


Sign In or Register to comment.