Starting and stopping the Google App Engine backends

I read the backend Google App Engine docs, but I still can't figure out how to start / stop backends (dynamic backends) from Python (using URLFetch, I think).

Can someone give me some sample code? The backend will not be included in the default version of the application.

+4
source share
2 answers

Depending on what type of backend you are using, "Resident Backends" cannot be disabled from the working environment only through the administrator console or on the command line, while "Dynamic Backends" will be disabled after a few minutes of inactivity.

So, if you use Dynamic Backends, you can simply send a request that says to stop what it is doing and it will be automatically disconnected.

http://code.google.com/intl/iw/appengine/docs/python/config/backends.html#Types_of_Backends

Edit

An example of how this might work:

from google.appengine.ext import webapp from google.appengine.api import memcache from google.appengine.ext.webapp.util import run_wsgi_app import time class ShutdownHandler(webapp.RequestHandler): def get(self): memcache.put('backendShutdown', True, 60) class StartHandler(webapp.RequestHandler): def get(self): lastCheck = time.time() while True: if time.time() - 60 > lastCheck: stopBackend = memcache.get('backendShutdown') if stopBackend: memcache.delete('backendShutdown') break lastCheck = time.time() if __name__ == '__main__': _handlers = [(r'/_ah/start', StartHandler), (r'/backend/worker/shutdown', ShutdownHandler)] # somekind of handler for shutdown run_wsgi_app(webapp.WSGIApplication(_handlers)) 

And to stop this, you should use:

 from google.appengine.api import backends, urlfetch url = backends.get_url('worker') + '/backend/worker/shutdown' urlfetch.fetch(url) 
+3
source

Use appcfg to start and stop backends. From the documentation :

appcfg backends <dir> start <backend>

Sets the backend state to START, allowing it to receive HTTP requests. Resident bases are launched immediately. Dynamic backups do not start until the first user request arrives. It has no effect if the backend has already begun.

appcfg backends <dir> stop <backend>

Sets the STOP backend status and exits all running instances. A stopped backend cannot receive HTTP requests; if it receives a request, it returns a 404 response. This command does not work if the backend has already been stopped.

+3
source

Source: https://habr.com/ru/post/1369378/


All Articles