Ejemplo n.º 1
0
def start_aps():
    try:
        # scheduler.init_app(app)
        scheduler.start()
        return jsonify({'msg': '定时任务开始成功', 'status': '200'})
    except Exception as e:
        raise e
Ejemplo n.º 2
0
def create_app(config_name=None):
    if config_name is None:
        config_name = os.getenv('FLASK_CONFIG', 'default')

    app = Flask(__name__)

    app.config['SECRET_KEY'] = 'xxxxxxxxx'

    app.debug = False
    toolbar = DebugToolbarExtension()
    toolbar.init_app(app)

    # 配置引入
    app.config.from_object(config[config_name])
    app.config.from_object(TaskConfig())
    app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False

    # 上下文推送
    #app.app_context().push()

    # 注册扩展
    register_extensions(app)
    register_blueprints(app)
    register_commands(app)

    # 启动apscheduler服务
    scheduler.start()

    # apscheduler api认证
    @scheduler.authenticate
    def authenticate(auth):
        return auth['username'] == 'guest' and auth['password'] == 'guest'

    return app
Ejemplo n.º 3
0
def register_extensions(app):
    """Register Flask extensions."""
    cors.init_app(app)
    webpack.init_app(app)
    socketio.init_app(app, message_queue='redis://')
    db.init_app(app)
    if not get_debug_flag():
        scheduler.init_app(app)
        scheduler.start()
        scheduler.run_job('missingcheck')
Ejemplo n.º 4
0
def config_scheduler(app):
    """Configure Scheduler"""
    # sche.init_app(app)
    scheduler.start()

    # 加载任务,选择了第一次请求flask后端时加载,可以选择别的方式...
    @app.before_first_request
    def load_tasks():
        # 开启任务
        from app.sche import run_tasks
Ejemplo n.º 5
0
def create_app(config_class=None):
    try:
        app = Flask(__name__)
        configure_app(app, config_class)
        configure_extensions(app)
        configure_logging(app)
        register_blueprint(app)
        scheduler.init_app(app)
        from app.task import test_task
        scheduler.start()
        return app
    except Exception as e:
        raise e
Ejemplo n.º 6
0
    def init_extensions(cls, _app):
        """
        初始化第三方插件
        :param _app:
        :return:
        """
        # extensions init
        # if _app.config['SENTRY_DSN']:
        #     sentry.init_app(_app, logging=_app.logger, level=_app.config['SENTRY_CONFIG']['level'])

        db.init_app(_app)

        redis.init_app(_app)

        # limiter.init_app(_app)

        flask_celery.init_app(_app)

        if config.ServiceEnum.is_job_service(_app.name):
            scheduler.init_app(_app)
            scheduler.start()
Ejemplo n.º 7
0
from flask import Flask

import atexit
from app.extensions import db, migrate, scheduler
from app.routes import prediction
from app.experiments import system_scheduler

scheduler.start()
atexit.register(lambda: scheduler.shutdown())


def create_app():
    app = Flask(__name__)
    app.config.from_object('config')

    db.init_app(app)
    migrate.init_app(app, db)

    app.register_blueprint(prediction, url_prefix='/api/v1/predictions')

    return app
Ejemplo n.º 8
0
 def run(self):
     with app.app_context():
         scheduler.start()
Ejemplo n.º 9
0
def register_extensions(app):
    db.init_app(app)
    db.app = app
    migrate.init_app(app, db)
    scheduler.init_app(app)
    scheduler.start()