Added extension (mime type) for job outputs
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Mon, 8 Nov 2010 20:27:43 +0000 (20:27 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Mon, 8 Nov 2010 20:27:43 +0000 (20:27 +0000)
bin/djais/models.py
bin/djais/views.py
bin/jobrunner.py
html_templates/jobs.html

index 310f4fff45470643a8db5601ea44e186682d3c38..ac4d461ceb86e7959d393be191b85edac05eb5a1 100644 (file)
@@ -212,6 +212,7 @@ class Job(models.Model):
     start_time = models.DateTimeField(blank=True, null=True)
     finish_time = models.DateTimeField(blank=True, null=True)
     command = models.TextField()
+    extension = models.CharField(max_length=8)
     pid = models.IntegerField(blank=True, null=True)
     result = models.IntegerField(blank=True, null=True)
 
index 62817cc8e284a072079d949dfe234f6b32ee33bd..789de7bf6168dc2911a3cc652ac2b01978d5835f 100644 (file)
@@ -413,6 +413,7 @@ def vessel_history(request, strmmsi, format=None):
             job = Job()
             job.user = request.user
             job.command = command
+            job.extension = u'kmz'
             job.save()
             request.user.info('Request queued as job %s' % job.id)
         else:
@@ -427,6 +428,7 @@ def vessel_history(request, strmmsi, format=None):
             job = Job()
             job.user = request.user
             job.command = command
+            job.extension = u'kmz'
             job.save()
             request.user.info('Request queued as job %s' % job.id)
         else:
@@ -441,6 +443,7 @@ def vessel_history(request, strmmsi, format=None):
             job = Job()
             job.user = request.user
             job.command = command
+            job.extension = u'csv'
             job.save()
             request.user.info('Request queued as job %s' % job.id)
         else:
index 1bfe97696e8805d3d0020e480fe717744f0ba497..54df472dada7b43aff3a706b74ae43c42bd07237 100755 (executable)
@@ -31,19 +31,19 @@ def main():
         logging.debug('Job %s is running: pid=%s', row[0], row[1])
         sys.exit(0)
 
-    sqlexec(u'SELECT id, command FROM job WHERE start_time IS NULL ORDER BY queue_time LIMIT 1')
+    sqlexec(u'SELECT id, command, extension FROM job WHERE start_time IS NULL ORDER BY queue_time LIMIT 1')
     row = get_common_cursor().fetchone()
     if row is None:
         logging.debug('Queue is empty.')
         sys.exit(0)
 
-    jobid, command = row
+    jobid, command, extension = row
     logging.info('Starting job %s: %s', jobid, command)
 
     sqlexec(u'UPDATE job SET start_time=now() WHERE id=%(jobid)s', {'jobid': jobid})
     dbcommit()
 
-    output = file('/var/lib/ais/jobs/'+unicode(jobid), 'wb')
+    output = file('/var/lib/ais/jobs/'+unicode(jobid)+'.'+extension, 'wb')
     p = subprocess.Popen(command, stdout=output, shell=True)
     logging.debug('System process id = %s', p.pid)
     sqlexec(u'UPDATE job SET pid=' + unicode(p.pid) + ' WHERE id=%(jobid)s', {'jobid': jobid})
index 683671fe946b283d9155b377f729da0d9c2b49d4..ab031f00288bcf08ce0737c25096849e98879ae3 100644 (file)
@@ -19,7 +19,7 @@ Command:<br>
 <tt>{{ job.command }}</tt><br>
 {% if job.finish_time %}
 Status: <b>Complete</b> in {{ job.process_time }} <br>
-Result: {% if job.result %}Error {{ job.result }}{% else %}Success<br><a href="/job_result/{{ job.id }}" class=button>download</a>{% endif %}<br>
+Result: {% if job.result %}Error {{ job.result }}{% else %}Success<br><a href="/job_result/{{ job.id }}.{{ job.extension }}" class=button>download</a>{% endif %}<br>
 {% else %}
     {% if job.start_time %}
     Status:<b>Running</b> since {{ job.start_time }}<br>