flaskapscheduler未在生产服务器上启动

2024-09-28 17:18:41 发布

您现在位置:Python中文网/ 问答频道 /正文

下面的代码在本地运行良好,但是当它在生产服务器上运行时,它根本不会启动。这两个设备使用相同版本的Python和Scheduler

@scheduler.task('interval', id='remove_basket_task', seconds=60*5, max_instances=1, misfire_grace_time=900)
def remove_baskets():

    with scheduler.app.app_context() as app:
        delete_all_old_baskets(time=app.app.config["ALLOWED_BASKET_TIME"])

def create_app(test_config=None):
    def is_werkzeug_reloader_process():
        """Get werkzeug status."""
        return os.environ.get("WERKZEUG_RUN_MAIN") == "true"
    # create and configure the app
    app = Flask(__name__)

    with app.app_context():

        app.config.from_object(ProductionConfig)


        from retrotex.main import main


        app.register_blueprint(main)
      
        scheduler.init_app(app)


        if not is_werkzeug_reloader_process():
            pass
        else:
            from .tasks import delete_all_old_baskets
            scheduler.start()

是什么导致了这个问题


Tags: fromconfigapptasktimemaindefwith