Author: eallen
Date: 2008-10-14 16:51:15 -0400 (Tue, 14 Oct 2008)
New Revision: 2639
Modified:
mgmt/trunk/cumin/python/cumin/job.py
mgmt/trunk/cumin/python/cumin/job.strings
mgmt/trunk/cumin/python/cumin/model.py
Log:
Defer fetching Job output until after page loads
Modified: mgmt/trunk/cumin/python/cumin/job.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/job.py 2008-10-14 20:49:59 UTC (rev 2638)
+++ mgmt/trunk/cumin/python/cumin/job.py 2008-10-14 20:51:15 UTC (rev 2639)
@@ -755,9 +755,6 @@
self.__fetch = self.FetchButton(app, "refresh")
self.add_child(self.__fetch)
- self.out_time = Attribute(app, "out_time")
- self.add_attribute(self.out_time)
-
self.ads = JobAdsSet(app, "ads")
self.add_child(self.ads)
@@ -770,6 +767,12 @@
self.user_file = Parameter(app, "user")
self.add_parameter(self.user_file)
+ self.output = self.OutputFile(app, "job_output")
+ self.add_child(self.output)
+
+ self.out_time = self.OutTime(app, "out_time")
+ self.add_child(self.out_time)
+
def get_args(self, session):
return self.frame.get_args(session)
@@ -815,15 +818,7 @@
return super(JobOutput, self).render(session, *args)
- def render_out_time(self, session, *args):
- now = datetime.now()
- return fmt_datetime(now, sec=True)
-
- def render_tail_js(self, session, *args):
- is_tail = self.first_last.get(session) == "t"
- return is_tail and "<script language=\"javascript\"
type=\"text/javascript\">addEvent(window, \"load\",
outputEnd);</script>" or ""
-
- def render_the_output(self, session, job):
+ def get_file_args(self, session):
first_last = self.first_last.get(session)
if first_last == "t":
start = -2048
@@ -832,9 +827,23 @@
start = 0
end = 2048
file = self.which_file.get_current_file_name(session)
- if file:
- action = self.app.model.job.fetch
- return action.do_invoke(job, file, start, end)
+ return (file, start, end)
+
+ class OutTime(AjaxField):
+ pass
+
+ class OutputFile(AjaxField):
+ def get_url(self, session):
+ job = self.parent.frame.get_args(session)[0]
+ if job:
+ file, start, end = self.parent.get_file_args(session)
+ fl = self.parent.first_last.get(session)
+ args = "%s&%i&%i&%s" % (file, start, end, fl)
+ args = escape_amp(args)
+ return "call.xml?class=job;id=%i;method=fetch;xargs=%s" %
(job.id, args)
+
+ def do_render(self, session):
+ return self.render_script(session)
class FetchButton(FormButton):
def render_content(self, session):
Modified: mgmt/trunk/cumin/python/cumin/job.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/job.strings 2008-10-14 20:49:59 UTC (rev 2638)
+++ mgmt/trunk/cumin/python/cumin/job.strings 2008-10-14 20:51:15 UTC (rev 2639)
@@ -262,7 +262,7 @@
[JobOutput.css]
-textarea#the_output {
+textarea#job_output {
height: 25em;
width: 100%;
border: 1px solid #EAEAEA;
@@ -287,7 +287,7 @@
}
}
function outputEnd() {
- var tarea = document.getElementById("the_output");
+ var tarea = document.getElementById("job_output");
if (tarea)
scrollToEnd(tarea);
}
@@ -298,10 +298,30 @@
<div class="rfloat">{first_last}</div>
{file}
</div>
-<div class="sactions refresh_info">{refresh} <h2>Last refresh was
at {out_time}</h2></div>
-<textarea name="the_output" id="the_output"
disabled="disabled" rows="20">
-{the_output}
+<div class="sactions refresh_info">{refresh} <h2>Last refresh was
at <span id="out_time">{out_time}</span></h2></div>
+<div><textarea name="job_output" id="job_output"
disabled="disabled" rows="20" cols="80">
+loading...{job_output}
</textarea>
-<div>{hidden_inputs}</div>
+{hidden_inputs}</div>
</form>
-{tail_js}
+
+[OutTime.javascript]
+function got_out_time(obj, id) {
+ var elem = document.getElementById(id);
+ if (elem) {
+ var str = obj.time.value;
+ elem.innerHTML = str;
+ }
+}
+[OutputFile.javascript]
+function got_job_output(obj, id) {
+ var elem = document.getElementById(id);
+ if (elem) {
+ var str = obj.fetch.output;
+ elem.value = str;
+ if (obj.fetch.tail == "t") {
+ outputEnd();
+ }
+ wooly.deferredUpdate('call.xml?class=job;id=0;method=gettime', got_out_time,
"out_time");
+ }
+}
Modified: mgmt/trunk/cumin/python/cumin/model.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/model.py 2008-10-14 20:49:59 UTC (rev 2638)
+++ mgmt/trunk/cumin/python/cumin/model.py 2008-10-14 20:51:15 UTC (rev 2639)
@@ -1888,6 +1888,9 @@
action = self.Fetch(self, "fetch")
action.navigable = False
+
+ action = self.GetTime(self, "gettime")
+ action.navigable = False
def get_title(self, session):
return "Job"
@@ -1969,8 +1972,14 @@
wait(predicate, timeout=20)
return self.job_ads
+ class GetTime(CuminAction):
+ def do_invoke(self, job):
+ now = datetime.now()
+ return "<time value=\"%s\" />" % fmt_datetime(now,
sec=True)
+
class Fetch(CuminAction):
- def do_invoke(self, job, file, start, end):
+ def do_invoke(self, job, *args):
+ file, start, end, tail = args
self.job_output = None
self.got_data = False
@@ -1998,7 +2007,7 @@
except Exception, e:
self.job_output = "Unable to get file at %s. Reason: %s" %
(file, e)
- return self.job_output and escape_entity(self.job_output)
+ return self.job_output and
"<fetch><output>%s</output><tail>%s</tail></fetch>"
% (escape_entity(self.job_output), tail)
class Hold(CuminAction):
def show(self, session, job):
@@ -2408,6 +2417,9 @@
self.__method = Parameter(app, "method")
self.add_parameter(self.__method)
+ self.__args = Parameter(app, "xargs")
+ self.add_parameter(self.__args)
+
def get_content_type(self, session):
return Page.xml_content_type
@@ -2417,14 +2429,19 @@
cls = self.__class.get(session)
id = self.__id.get(session)
+ xargs = self.__args.get(session)
if cls:
- object = cls.mint_class.get(id)
+ try:
+ object = cls.mint_class.get(id)
+ except:
+ object = None
method = self.__method.get(session)
#self.app.model.write_xml(writer, objects)
for action in cls.actions:
if action.name == method:
- data = action.do_invoke(object)
+ args = xargs and xargs.split("&") or list()
+ data = action.do_invoke(object, *args)
self.write_xml(writer, data)
return writer.to_string()