在一天中的特定时间使用gunicorn运行网络应用程序的最佳方式是什么



我有一个用python-dash运行的小仪表板,我已经使用GUNICORN在生产中成功部署了它。

然而,我只想在生产时间(比如8:00到20:00(运行它。最好的方法是什么?使用crontab运行GUNICORN发射线?在用noHup启动GUNICORN过程后,在一天结束时使用crontab来杀死它?

谢谢!

一种可能的方法是直接在Dash应用程序中添加逻辑,即类似的东西

import dash
import dash_html_components as html
import datetime
def the_actual_layout():
return html.Div("Hello world!")
def layout():
hour = datetime.datetime.now().hour
# If we are outside business hours, return an error message.
if(hour < 8 or hour > 19):
return html.Div("The app is only available between 08:00 and 20:00, please come back tomorrow.")
# Otherwise, render the app.
return the_actual_layout()
app = dash.Dash()
app.layout = layout
if __name__ == '__main__':
app.run_server()    

这将因此消除对启动/停止应用程序的外部工具的需要。

最新更新