Start backend with async urlfetch on Google App Engine

不羁岁月 提交于 2019-12-10 06:43:24

问题


I am experimenting with several of GAE's features.

I 've built a Dynamic Backend but I am having several issues getting this thing to work without task queues

Backend code:

class StartHandler(webapp2.RequestHandler):

    def get(self):
    #... do stuff...    

if __name__ == '__main__':
    _handlers = [(r'/_ah/start', StartHandler)]
    run_wsgi_app(webapp2.WSGIApplication(_handlers))

The Backend is dynamic. So whenever it receives a call it does it's stuff and then stops.

Everything is worikng fine when I use inside my handlers:

url = backends.get_url('worker') + '/_ah/start'
urlfetch.fetch(url)

But I want this call to be async due to the reason that the Backend might take up to 10 minutes to finish it's work.

So I changed the above code to:

url = backends.get_url('worker') + '/_ah/start'
rpc = urlfetch.create_rpc()
urlfetch.make_fetch_call(rpc, url)

But then the Backend does not start. I am not interested into completion of the request or getting any data out of it.

What am I missing - implementing wrong?

Thank you all


回答1:


Using RPC for async call without calling get_result() on the rpc object will not grantee that the urlfetch will be called. Once your code exits the pending async calls that were not completed will be aborted.

The only way to make the handler async is to queue the code in a push queue.



来源:https://stackoverflow.com/questions/13937556/start-backend-with-async-urlfetch-on-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!