Hi django-users,

I've come looking for some advice.  I've built a json api using django, and
POST/PUT to one of my endpoints does some non-trivial processing.  The
gritty details are included at the end, but for the purposes of this
discussion, the important things are probably 1) The action is for
processing a user's previously uploaded data, 2) it takes a long time to
complete, and 3) probably doesn't make sense to spread over multiple api
calls.  The work that's done can take multiple minutes to complete, which
is an awful long time to wait for an http response to event begin (right?
 Or am I mistaken, there?).  Right now, that's what I'm doing.  The client
just has to wait until the processing is finished to get the response.
 This is functional, but I'm considering what can be done to make for a
better user experience and/or make it less fragile (I'm honestly not sure
what would happen if the connection died before the response goes out).

So my question is, what are my options, here?  I'm thinking the api could
respond immediately with a message like, "cool, I'll get right on that!"
and the heavy lifting happens in the background sometime after the response
goes out.  What constructs in django or python best facilitate that?  Then
what do I tell the client?  "Poll the api until it's done."?  I could also
maybe keep it all in one request like it is now, and stream progress
information back to the client as the process does stuff.  What other
approaches are there?  Am I over-thinking this? :-P  Any wisdom would be
appreciated!

Thanks!
jpk


P.S. - The gritty details:  The api call in question takes an image (that
the user previously uploaded) and a set of ground control points (pairs of
longitude,latitude on the world and x,y on the image) to generate map tiles
of the image that can be overlayed on world map tiles.  Tools from OSGeo's
excellent GDAL library are used to do this, then all the tiles are shipped
off to S3.  Once this is finished, the client has a url it can use to grab
tiles (this url is stored in the database, accessible via later api calls,
and also included in the response generated after all that processing is
done).  There's still lots I can do to optimize this process, but I don't
expect it can be made near-instant.  The other component to this is the
frontend: written using backbone.js.  I'm already using a custom
Backbone.sync(), so I suppose extra gymnastics in there (particularly in
the case of streaming progress information) to support whatever I do in the
backend related to this wouldn't be out of bounds.


-- 
john p. kiffmeyer

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to