Bugfix: Do not use job.save() because object is updated by other process
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sat, 13 Nov 2010 14:55:49 +0000 (14:55 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Sat, 13 Nov 2010 14:55:49 +0000 (14:55 +0000)
Use Job.objects.update() instead

bin/djais/views.py

index 1a3f8506d3d47c05b363b74ea01e6daf69dd869c..f26c14495d823bd953620b74ca136fe7878489d6 100644 (file)
@@ -756,8 +756,8 @@ def job_detail(request, jobid):
         # finished but not archived:
         # TODO: use hostname
         response['Refresh'] = '0;url=https://ais.nirgal.com/job/%s/download' % job.id
-        job.archive_time = datetime.utcnow()
-        job.save()
+        # careful not to modify other unschronized columns
+        Job.objects.filter(id=jobid).update(archive_time = datetime.utcnow())
     return response
 
 @http_authenticate(auth, 'ais')
@@ -771,15 +771,16 @@ def job_get(request, jobid):
         total_wait += 1
         if total_wait > 15:
             request.user.info('Your query is slow. Please be patient.')
+            # TODO: Do not overwrite job.finishtime / result
             if not job.notify:
-                job.notify = 'W' # Web
-                job.save()
+                # careful not to modify other unschronized columns
+                Job.objects.filter(id=jobid).update(notify = 'W') # Web
             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()
+        # careful not to modify other unschronized columns
+        Job.objects.filter(id=jobid).update(archive_time = datetime.utcnow())
 
     if job.result:
         # Error occured