Fixed datetime of processes when computer is not GMT set
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Wed, 5 Jan 2011 17:12:15 +0000 (17:12 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Wed, 5 Jan 2011 17:12:15 +0000 (17:12 +0000)
Dynamic base host name

bin/djais/models.py
bin/djais/views.py
bin/jobrunner.py
bin/show_targets_ships.py

index a6e3d3e29dcad04ba81edbb560886cd240aaff45..b8404460498064c405b195b010cf8737b61b3950 100644 (file)
@@ -211,7 +211,7 @@ class Job(models.Model):
     
     id = models.CharField(primary_key=True, max_length=8, default=make_unique_job_id)
     user = models.ForeignKey(User)
-    queue_time = models.DateTimeField(auto_now_add=True)
+    queue_time = models.DateTimeField() #auto_now_add=True) is buggy, not GMT
     start_time = models.DateTimeField(blank=True, null=True)
     finish_time = models.DateTimeField(blank=True, null=True)
     command = models.TextField()
index 54713f91539ee4abcef02530aadee6615176ef35..baef44bad28b98fd11922679c5d690db63352d7d 100644 (file)
@@ -530,6 +530,7 @@ def vessel_history(request, strmmsi):
             command += u' ' + strmmsi
 
             job = Job()
+            job.queue_time = datetime.utcnow()
             job.friendly_filename = u'%s.%s' % (strmmsi, extension)
             job.user = request.user
             job.command = command
@@ -754,6 +755,7 @@ def fleet_history(request, fleetname):
             command += u' @' + fleetname
 
             job = Job()
+            job.queue_time = datetime.utcnow()
             job.friendly_filename = u'%s.%s' % (fleetname, extension)
             job.user = request.user
             job.command = command
@@ -788,8 +790,7 @@ def job_detail(request, jobid):
         response['Refresh'] = 5
     elif not job.archive_time:
         # finished but not archived:
-        # TODO: use hostname
-        response['Refresh'] = '0;url=https://ais.nirgal.com/job/%s/download' % job.id
+        response['Refresh'] = '0;url=https://' + request.get_host() + '/job/%s/download' % job.id
         # careful not to modify other unschronized columns
         Job.objects.filter(id=jobid).update(archive_time = datetime.utcnow())
     return response
index d772924a62a573428e6232ebfabe828b4a69a9df..d9ed8096a2693cdf8daa96cd06fcbd5a68778099 100755 (executable)
@@ -56,7 +56,7 @@ def runjob():
     """
     # remove jobs archived for more than 1 day
     deleted_jobs = []
-    sqlexec(u"SELECT id, friendly_filename FROM job WHERE archive_time < now() - '%s'::interval" % ARCHIVE_EXPIRE)
+    sqlexec(u"SELECT id, friendly_filename FROM job WHERE archive_time < now() AT TIME ZONE 'GMT' - '%s'::interval" % ARCHIVE_EXPIRE)
     while True:
         row = get_common_cursor().fetchone()
         if row is None:
@@ -82,7 +82,7 @@ def runjob():
     command = 'python -m ais.' + command
     logging.info('Starting job %s: %s', jobid, command)
 
-    sqlexec(u'UPDATE job SET start_time=now() WHERE id=%(jobid)s', {'jobid': jobid})
+    sqlexec(u"UPDATE job SET start_time=now() AT TIME ZONE 'GMT' WHERE id=%(jobid)s", {'jobid': jobid})
     dbcommit()
 
     filename = jobid_ext_to_filename(jobid, friendly_filename)
@@ -94,7 +94,7 @@ def runjob():
     dbcommit()
     
     returncode = p.wait()
-    sqlexec(u'UPDATE job SET pid=NULL, finish_time=now(), result=' + unicode(returncode) + ' WHERE id=%(jobid)s', {'jobid': jobid})
+    sqlexec(u"UPDATE job SET pid=NULL, finish_time=now() AT TIME ZONE 'GMT', result=" + unicode(returncode) + " WHERE id=%(jobid)s", {'jobid': jobid})
     dbcommit()
     logging.info('Job complete: result=%s', returncode)
 
index 9d3b58325d8218779a16fbea00d30225d43517b7..da1ba6f92f7324d51d9cbb32c2147444c7f151f3 100755 (executable)
@@ -13,6 +13,8 @@ from ais.common import *
 from ais.area import load_area_from_kml_polygon
 from ais.ntools import datetime_to_timestamp, xml_escape
 
+from ais.djais.settings import AIS_BASE_URL
+
 __all__ = [ 'format_fleet', 'format_boat_intime', 'format_boat_track', 'STYLE', 'KML_DISPLAYOPT_NONAMES', 'KML_DISPLAYOPT_HISTORICAL', 'KML_DISPLAYOPT_SOURCES', 'kml_to_kmz' ]
 
 
@@ -314,7 +316,7 @@ def format_boat_data(nmea, timeinfo=None, display_options=0):
         if source_5 and source_1 != source_5:
             result += u', '+ Nmea.format_source(source_5)
         result += u'<br>\n'
-    result += u'<a href="https://ais.nirgal.com/vessel/%(mmsi)s/">More...</a>' \
+    result += u'<a href="' + AIS_BASE_URL + u'/vessel/%(mmsi)s/">More...</a>' \
               % {'mmsi': mmsi}
     result += u']]>\n'
     result += u'</description>\n'