google app engine - GAE Having Tasks generate pages for user -


I have a web app that I would like to get the following functionality:

  1. User A
  2. Webpad receives JS data from that URL and other people from the same website (this can take anywhere from 1-10 seconds)
  3. WebApps Uses data to generate a page for the user

With this viewpoint, I believe that If the server is in the process of getting data for a user, then the other user will not be able to load the page (server busy). If possible, I would like to avoid it.

It seems that the Google Tasks API would be useful, but I do not think how I can run the job, and then use the output of the job

What is the best way to solve?

Thanks in advance

Some thoughts:

1) The app engine can make more than one request at a time. Try it - App Engine will probably spin more than one instance of your app => Multiple requests can be made at one time, with the request over time so long, although I do not expect that it will be on a much larger scale (They recommend request / response time within one second).

2) If you want to quickly return the user, as you suggested, you could have enclosed in the work queue. After this, the user's webpage (using the meta tag, http-equiv or javascript) voted to see the server every two seconds, whether the page is ready or not.

3) If the generated page is needed again, then you should consider remembering it to try to save it again. With 10 seconds of load times, you can also consider storing them in datastore for a short time (if caching is appropriate for your app).

Here is a very basic example of how you can do this:

  Import from google.appengine.api.labs Import Tasksq.Google.appengine.ext Import Webapp import run_wsgi_app class BuildPage (db.Model) from DB, googleapp.appengine.ext.webapp.util: Html = db.TextProperty () Category PageBuilder (webapp.RequestHandler): "Handler" by the job queue to create the page "Is called. "" Df Post (self): key = self.request.get ('key') Url = self.request.get ('url') Import Time Time (5) # Excuse This page takes a little time to make html = "You asked for% s"% url # To create the original stuff here ... bitpages (key_name = key, html = html) .put ( ) # Errors should be checked ... def html_to_redir_to_built_page (hexci): "page to display when we wait. Created page." "New_url = '/ get_built_page? K = '+ Okhi refresh_tag =' & lt; Meta http-equiv = "Refresh" content = "2;% s" /> % New_url return '& lt; Html & gt; & Lt; Head & gt;% s & lt; / Head & gt; & Lt; Body & gt; Please wait & lt; / Body & gt; & Lt; / Html> % Refresh_tag class BuildPageForURL (webapp.RequestHandler): Request a user to create a page for the request URL. Get "def" (self): url = self.request.get ('url') key = Hashlib.md5 (url) .hexdigest () # Optimization: Check it for datastore to see it was already generated Do you? TaskQ.ad () = "/ buildit", params = dict (key = key, url = url)) self.redirect ('/ get_built_page? K =' + key) class GetBuiltPage (webapp.RequestHandler): "Return" If it is ready, then it returns a page, otherwise returns a page which is later "def" (self): key = self.request.get ('k') bp = BuiltPage.get_by_key_name (key) If BP: Self Response.out.write (bp.html) # If you know it is clear that this is a 1-time request: bp.delete () Other: self.response.out.write (html_to_redir_to_built_page ( Key)) application = webapp.WSGIApplication (('/', BuildPageForURL), ('/ buildit', PageBuilder), ('/ get_built_page', GetBuiltPage)]) Ky (): run_wsgi_app (application) that __name__ == '__main__': main ()  

Comments