Python后台计划程序未在Elastic Beanstalk上运行

Python后台计划程序未在Elastic Beanstalk上运行,python,amazon-elastic-beanstalk,python-multithreading,wsgi,apscheduler,Python,Amazon Elastic Beanstalk,Python Multithreading,Wsgi,Apscheduler,我在我的flask服务器上安排了一个简单的基于cron的计划任务,该服务器托管在elastic beanstalk上。调度程序的时区设置为UTC,它应该在每天14小时(我当地时间上午8点)运行,我在本地尝试过,它在那个时间运行,但在托管时似乎从未运行过(因为我看不到应用程序的相应更新,也看不到日志中的任何内容)。也许我对apscheduler的工作原理有一些误解?有什么建议吗?下面是我的一些代码片段,我只是启动了flask应用程序,并在主函数中启动了调度程序,顶级范围中的某个地方是我的调度程序的

我在我的flask服务器上安排了一个简单的基于cron的计划任务,该服务器托管在elastic beanstalk上。调度程序的时区设置为UTC,它应该在每天14小时(我当地时间上午8点)运行,我在本地尝试过,它在那个时间运行,但在托管时似乎从未运行过(因为我看不到应用程序的相应更新,也看不到日志中的任何内容)。也许我对apscheduler的工作原理有一些误解?有什么建议吗?下面是我的一些代码片段,我只是启动了flask应用程序,并在主函数中启动了调度程序,顶级范围中的某个地方是我的调度程序的init。下面是在本地正常工作的计划作业,但不是在beanstalk上

编辑:我通过将scheduler.start()和.add_作业放在一个带有before_first_请求装饰器的函数中来实现它,但我不确定为什么这样做。有人能解释或提供更好的替代方案吗

#Scheduler
scheduler = BackgroundScheduler(timezone='UTC')

@scheduler.scheduled_job('cron', day_of_week='mon-sun', hour=14, minute=0)
def update_tracker_prices_and_tweets_and_news():
    print('in scheduler 1')
    connection = connect_to_postgres()
    cursor = connection.cursor()
    try:
        cursor.execute("SELECT ticker FROM Trackers")
    except Exception as e:
        return {'error': str(e)}
    tickers = [record[0] for record in cursor]
    print('in scheduler got all tickers')
    for ticker in tickers:
        try:
            cursor.execute("CALL remove_old_price_data(%s);", (ticker,))
        except Exception as e:
            print({'error': e})
            continue
        print('in scheduler updating price data')
        try:
            util.add_daily_closing_price(ticker, session, connection, cursor)
        except Exception as e:
            print({'error': e})
        try:    
            util.add_daily_minute_price(ticker, session, connection, cursor)
        except Exception as e:
            print({'error': e})
        update_news(ticker)
    print('in scheduler successfully updated all data possible')
    connection.commit()
    cursor.close()
    connection.close()
    return {'success': 'SUCESSFULLY UPDATED ALL PRICE AND TWEET DATA FOR ALL TRACKED TICKERS'}

if __name__ == '__main__':
    scheduler.start()
    application.run()