=== modified file 'lava_scheduler_daemon/dbjobsource.py'
@@ -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):