[Baypiggies] Programming Pattern/Django/Best Practice?
Glen Jarvis
glen at glenjarvis.com
Thu Apr 2 10:40:43 CEST 2009
I need a little help. Anytime I find myself walking off the well worn
path I have to ask myself "I bet someone has been here before.... let
me see what they did in this situation."
I have a program pattern that goes something like this:
1) Special event occurs, causing a page to be loaded, and therefore
Django to process an event.
2) The initial processing is executed very quick/simple
3) Depending upon step 2, a different Python routine will be executed
(maybe not even in Django/Maybe as a subprocess)
4) The page is displayed to the user who triggered the event in step 1.
5) User can click a 'link' in the page displayed in step 4 to check on
status of event triggered
6) If the process has not completed, this new page will indicate this;
User can reclick and go to step 5. If it has, the new page will be the
results of that process. The process is complete.
Now, thus far, timing has not been an issue - but I've not tested
under a heavy load, so I'm sure it will be over time. Steps 1, 2 and 4
can be done in very reasonable time and the user sees no real delay.
I have two [now 3] approaches I am considering, but both feel very
hackish....
Approach #1
-----------------
a. In step 2 above, a guaranteed unique new static page is generated
(e.g., 534d423d.html). The contents of this page is "Not complete.
Click to check again." The link is the page itself (e.g., 534d423d.html)
b. Whenever the Python routine in step 3 is complete, it replaces the
page (i.e., 534d423d.html) with the results data information and the
process is over
The strength of this approach is that we're now only dealing with
static pages. Efficiency is high. And the process is simple.
The weakness of this approach is that there's no way to clean up these
'unique' pages except at a later time (by comparing timestamps from
when the file was created). I see capacity planning problems with this.
Approach #2
------------------
A similar approach but with dynamically created urls for this
guaranteed uniqueness. I don't know how this can be done truly
dynamically since urls.py is not something we want to reinterpret each
time. The more I think about the strengths and weaknesses of this
approach, the less I see a benefit of doing it this way. I also
predict Django will not play nicely with me when I step outside 'the
box' with this one.
Approach #3 (Discovered right before sending)
-----------------
[Doh! Ajax would be a very simple solution here.]
This seems to be a fairly common 'cycle' in web programming. I've seen
the pattern many times before in clumsier days with clumsier tools.
Does this have a name? Is there any standard approach anyone takes?
Best yet, is there a python module already out there that someone
knows about that facilities and manages approach #1? Is there a
third approach I hadn't considered? [DOH! Just before sending this,
I hit myself in the forehead and think of an Ajax approach]. I *must*
have this disconnect at step 3 because I cannot guarantee any timely
response from the routine to be executed. In fact, some of these
routines will be written by others in the future... it's a
configurable system where the routine can be plugged in via an API.
You've already been helpful for being a sounding board comparing these
approaches.
Cheers,
Glen
--
415-680-3964
glen at glenjarvis.com
"You must be the change you wish to see in the world." -M. Gandhi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20090402/6a61173b/attachment.htm>
More information about the Baypiggies
mailing list