예제 #1
0
def run_as_task(func, *args, **kwargs):
    app = create_app()
    app.app_context().push()

    # print("ARGS:", args)
    app.logger.info(f'Adding task {func.__name__} to RQ')
    try:
        func(*args, **kwargs)
        set_task_progress(100)
        app.logger.info(f'Task {func.__name__} completed successfully')
    except Exception as e:
        db.session.rollback()
        m = getattr(e, 'message', repr(e)).encode().decode('unicode_escape')
        set_task_progress(100, 'failed', m)
        app.logger.error(f'{func.__name__} failed due to unhandled exception', exc_info=sys.exc_info())
예제 #2
0
파일: tests.py 프로젝트: MakeICT/MCP-Server
 def setUp(self):
     self.app = create_app(TestConfig)
     self.app_context = self.app.test_request_context()
     self.app_context.push()
     self.client = self.app.test_client()
     db.create_all()
예제 #3
0
파일: tests.py 프로젝트: MakeICT/MCP-Server
 def setUp(self):
     self.app = create_app(TestConfig)
     self.app_context = self.app.app_context()
     self.app_context.push()
     db.create_all()
예제 #4
0
import argparse
from mcp import create_app

# Create the flask app.
app = create_app()

# Run the app
if __name__ == '__main__':

    # Define the arguments.
    parser = argparse.ArgumentParser()
    parser.add_argument('--host', default='0.0.0.0', help='Host to bind to: [%(default)s].')
    parser.add_argument('--port', type=int, default=app.config['SERVER_PORT'], help='Port to listen to: [%(default)s].')
    parser.add_argument('--debug', action='store_true', default=False, help='Debug mode: [%(default)s].')

    # Parse arguemnts and run the app.
    args = parser.parse_args()
    app.run(debug=args.debug, host=args.host, port=args.port)