views:

29

answers:

3

Hi,

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

A: 

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.

Adam Crossland
Well, not really what I'm after. I want it the other way around. I want the server to runt the script when it starts.
fredrik
I'm sorry that it's not what you're after, but it will work. Your other options are hacking dev_appserver.py or putting code into the main function of your AppEngine application. The first option is a terrible idea because you really don't want to go branching the AppEngine framework, and your change will get lost every time that you install a new version of AppEngine. The second option technically runs after the server has started, and it is also likely to break when deployed to production. I didn't want to simply answer "No" to your question, so I gave you an option.
Adam Crossland
+2  A: 

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.

dar
Thanks, works great!
fredrik
A: 

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.

Vladimir Prudnikov