Try to download queued job result ASAP.
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 11 Nov 2010 03:02:16 +0000 (03:02 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Thu, 11 Nov 2010 03:02:16 +0000 (03:02 +0000)
Print "slow" warning message, and show job watch after a while.

bin/djais/models.py
bin/djais/views.py

index aa7f0b80e61b0b692f85366dbe4316fbd45a8365..b9d5169ad308a9385560d9a50df4b39a5eb4d9e9 100644 (file)
@@ -230,6 +230,8 @@ class Job(models.Model):
         dt = self.finish_time - self.start_time
         return nice_timedelta_str(dt)
 
+    # TODO: parse and display /proc/%pid/stat see "man 5 proc"
+
     class Meta:
         db_table = u'job'
         ordering = ('queue_time',)
index 25f9b17e136b6ca8132c44fa0eaabaaad63fd1ef..0b48b767d71951f8ff78732df172ec194ec34c1b 100644 (file)
@@ -8,7 +8,7 @@ import os
 import os.path
 from datetime import *
 import re
-from time import time as get_timestamp
+from time import time as get_timestamp, sleep
 import logging
 import crack
 import struct
@@ -422,7 +422,7 @@ def vessel_history(request, strmmsi, format=None):
             #request.user.info('Request queued as job %s' % job.id)
             if not jobrunner.wakeup_daemon():
                 return HttpResponseServerError(jobrunner.DAEMON_WAKEUP_ERROR)
-            return HttpResponseRedirect('/job/%s/' % job.id)
+            return HttpResponseRedirect('/job/%s/download' % job.id)
         else:
             value = kml_to_kmz(format_boat_track(nmea_iterator))
             response = HttpResponse(value, mimetype="application/vnd.google-earth.kml")
@@ -440,7 +440,7 @@ def vessel_history(request, strmmsi, format=None):
             #request.user.info('Request queued as job %s' % job.id)
             if not jobrunner.wakeup_daemon():
                 return HttpResponseServerError(jobrunner.DAEMON_WAKEUP_ERROR)
-            return HttpResponseRedirect('/job/%s/' % job.id)
+            return HttpResponseRedirect('/job/%s/download' % job.id)
         else:
             value = kml_to_kmz(format_boat_intime(nmea_iterator))
             response = HttpResponse(value, mimetype="application/vnd.google-earth.kml")
@@ -458,7 +458,7 @@ def vessel_history(request, strmmsi, format=None):
             #request.user.info('Request queued as job %s' % job.id)
             if not jobrunner.wakeup_daemon():
                 return HttpResponseServerError(jobrunner.DAEMON_WAKEUP_ERROR)
-            return HttpResponseRedirect('/job/%s/' % job.id)
+            return HttpResponseRedirect('/job/%s/download' % job.id)
         else:
             value = StringIO()
             output = csv.writer(value)
@@ -700,9 +700,19 @@ def job_get(request, jobid):
     job = get_object_or_404(Job, id=jobid)
     if job.user != request.user:
         return HttpResponseForbidden('403 Forbidden')
+    total_wait = 0
+    while not job.finish_time:
+        sleep(1)
+        total_wait += 1
+        if total_wait > 30:
+            request.user.info('Your query is slow. Please be patient.')
+            return HttpResponseRedirect('/job/%s/' % job.id)
+        job = get_object_or_404(Job, id=jobid)
+    
     if not job.archive_time:
         job.archive_time = datetime.utcnow()
         job.save()
+
     extension = os.path.splitext(job.friendly_filename)[-1]
     return HttpResponseRedirect('/job_result/%s%s/%s' % (job.id, extension, job.friendly_filename))