diff mbox

[Branch,~linaro-validation/lava-scheduler/trunk] Rev 86: try a bit harder to fix bug 861149 in all cases

Message ID 20111019021412.14211.54799.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Michael-Doyle Hudson Oct. 19, 2011, 2:14 a.m. UTC
Merge authors:
  Michael Hudson-Doyle (mwhudson)
Related merge proposals:
  https://code.launchpad.net/~mwhudson/lava-scheduler/workaround-django-tz-bug-861149/+merge/79634
  proposed by: Michael Hudson-Doyle (mwhudson)
  review: Approve - Zygmunt Krynicki (zkrynicki)
------------------------------------------------------------
revno: 86 [merge]
committer: Michael Hudson-Doyle <michael.hudson@linaro.org>
branch nick: trunk
timestamp: Wed 2011-10-19 15:12:33 +1300
message:
  try a bit harder to fix bug 861149 in all cases
modified:
  lava_scheduler_daemon/dbjobsource.py


--
lp:lava-scheduler
https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk

You are subscribed to branch lp:lava-scheduler.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava_scheduler_daemon/dbjobsource.py'
--- lava_scheduler_daemon/dbjobsource.py	2011-10-17 23:35:27 +0000
+++ lava_scheduler_daemon/dbjobsource.py	2011-10-19 01:40:01 +0000
@@ -56,8 +56,18 @@ 
     def getBoardList(self):
         return self.deferForDB(self.getBoardList_impl)
 
-    @transaction.commit_on_success()
+    @transaction.commit_manually()
     def getJobForBoard_impl(self, board_name):
+        # If there is no db connection yet on this thread, create a connection
+        # and immediately commit, because rolling back the first transaction
+        # on a connection loses the effect of settings.TIME_ZONE when using
+        # postgres (see https://code.djangoproject.com/ticket/17062) and this
+        # method has to be able to roll back to avoid assigning the same job
+        # to multiple boards.
+        if connection.connection is None:
+            connection.cursor().close()
+            assert connection.connection is not None
+            transaction.commit()
         while True:
             device = Device.objects.get(hostname=board_name)
             if device.status != Device.IDLE:
@@ -85,6 +95,9 @@ 
                     # same job -- this is an application level bug though.
                     device.save()
                 except IntegrityError:
+                    self.logger.info(
+                        "job %s has been assigned to another board -- "
+                        "rolling back", job.id)
                     transaction.rollback()
                     continue
                 else:
@@ -93,8 +106,15 @@ 
                     job.save()
                     json_data = json.loads(job.definition)
                     json_data['target'] = device.hostname
+                    transaction.commit()
                     return json_data
             else:
+                # We don't really need to rollback here, as no modifying
+                # operations have been made to the database.  But Django is
+                # stupi^Wconservative and assumes the queries that have been
+                # issued might have been modifications.
+                # See https://code.djangoproject.com/ticket/16491.
+                transaction.rollback()
                 return None
 
     def getJobForBoard(self, board_name):