Running script on server start in google app engin

2019-05-02 03:22发布

Is it possible to run a script each time the dev server starts? Also at each deploy to google?

I want the application to fill the database based on what some methods returns.

Is there any way to do this?

..fredrik

4条回答
可以哭但决不认输i
2楼-- · 2019-05-02 03:31

Warmup Requests in combination with min_idle_instances will probably work in your deploy usecase.

查看更多
手持菜刀,她持情操
3楼-- · 2019-05-02 03:34

You can do this by writing a script in your favorite scripting language that performs the actions that you desire and then runs the dev server or runs appcfg.py update.

查看更多
狗以群分
4楼-- · 2019-05-02 03:39

I use appengine python with the django helper. As far as I know you cannot hook anything on the deploy, but you could put a call to check if you need to do your setup in the main function of main.py. This is how the helper initializes itself on the first request. I haven't looked at webapp in a while, but I assume main.py acts in a similar fashion for that framework.

Be aware that main is run on the first request, not when you first deploy. It will also happen if appengine starts up a new instance to handle load, or if all instances were stopped because of inactivity. So make sure you check to see if you need to do your initialization and then only do it if needed.

查看更多
时光不老,我们不散
5楼-- · 2019-05-02 03:47

Try to make wrapper around the server runner and script that run deployment. So you will be able to run custom code when you need.

查看更多
登录 后发表回答