예제 #1
0
파일: __init__.py 프로젝트: Maxcutex/pm_api
def create_app(config_name):
    app = FlaskAPI(__name__, instance_relative_config=False)
    app.config.from_object(env.app_env[config_name])
    app.config.from_pyfile("../config/env.py")
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
    app.config["CORS_HEADERS"] = "Content-Type"

    # CORS

    CORS(app)
    # CORS(app, resources={r"/api/*": {"origins": "http://localhost:3000"}})

    # Blueprints
    blueprint = BaseBlueprint(app)
    blueprint.register()

    from . import models

    db.init_app(app)

    # handle_exceptions(app)
    #
    # # register error handlers
    # app.register_error_handler(Exception, handle_exception)
    # app.register_error_handler(
    #     BaseModelValidationError, handle_exception)

    return app
예제 #2
0
def create_app(config_name):
    app = FlaskAPI(__name__, instance_relative_config=False)
    app.config.from_object(env.app_env[config_name])
    app.config.from_pyfile('../config/env.py')
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    # CORS
    CORS(app)

    # Blueprints
    blueprint = BaseBlueprint(app)
    blueprint.register()

    from . import models
    db.init_app(app)

    return app
예제 #3
0
def create_app(config_name):
    app = FlaskAPI(__name__, instance_relative_config=False)
    app.config.from_object(env.app_env[config_name])
    app.config.from_pyfile('../config/env.py')
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.url_map.converters['date'] = DateValidator
    app.url_map.strict_slashes = False

    # CORS
    CORS(app)

    # Blueprints
    blueprint = BaseBlueprint(app)
    blueprint.register()

    # cron = Cron(app)
    # scheduler = BackgroundScheduler("Africa/Lagos")
    # # in your case you could change seconds to hours
    # scheduler.add_job(cron.run_24_hourly, trigger='interval', hours=24)
    # scheduler.add_job(cron.meal_session_cron)
    # scheduler.start()

    from . import models
    db.init_app(app)

    cron = Cron(app)
    scheduler = BackgroundScheduler(timezone="Africa/Lagos")
    # in your case you could change seconds to hours
    scheduler.add_job(cron.run_24_hourly, trigger='interval', hours=24)
    scheduler.add_job(cron.run_meal_session_cron,
                      'cron',
                      day_of_week='mon-fri',
                      hour=0,
                      minute=0,
                      misfire_grace_time=None)
    scheduler.add_job(cron.run_5_minute, trigger='interval', minutes=5)
    scheduler.start()

    swg = Swagger(app)
    handle_exceptions(app)

    # register error handlers
    app.register_error_handler(Exception, handle_exception)
    app.register_error_handler(BaseModelValidationError, handle_exception)

    return app
예제 #4
0
    celery = Celery(
        app.import_name,
        broker=app.config['BROKER_URL']
    )
    celery.conf.update(app.config)
    celery.config_from_object(celeryconflig)
    TaskBase = celery.Task

    class ContextTask(TaskBase):
        abstract = True

        def __call__(self, *args, **kwargs):
            with app.app_context():
                return TaskBase.__call__(self, *args, **kwargs)

    celery.Task = ContextTask

    return celery


app = create_app(get_env('APP_ENV'))

celery = make_celery(app)

bcrypt = Bcrypt(app)
mail = Mail(app)

db.init_app(app)

blueprint = BaseBlueprint(app)
blueprint.register()