Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running script on server start in google app engine, in Python

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

like image 863
fredrik Avatar asked Feb 12 '10 15:02

fredrik


People also ask

How do you deploy code written in Python for the client's use?

To deploy, you need to upload this artifact to your production machine. To install it, just run dpkg -i my-package. deb . Your virtualenv will be placed at /usr/share/python/ and any script files defined in your setup.py will be available in the accompanying bin directory.


1 Answers

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.

like image 62
dar Avatar answered Nov 10 '22 00:11

dar