def __updateJobResults(self):
isSaved = False<EOL>while True:<EOL><INDENT>self._isBestModel, jobResults, jobResultsStr =self.__checkIfBestCompletedModel()<EOL>if self._isBestModel:<EOL><INDENT>if not isSaved:<EOL><INDENT>self.__flushPredictionCache()<EOL>self._jobsDAO.modelUpdateTimestamp(self._modelID)<EOL>self.__createModelCheckpoint()<EOL>self._jobsDAO.modelUpdateTimestamp(self._modelID)<EOL>isSaved = True<EOL><DEDENT>prevBest = jobResults.get('<STR_LIT>', None)<EOL>prevWasSaved = jobResults.get('<STR_LIT>', False)<EOL>if prevBest == self._modelID:<EOL><INDENT>assert not prevWasSaved<EOL><DEDENT>metrics = self._getMetrics()<EOL>jobResults['<STR_LIT>'] = self._modelID<EOL>jobResults['<STR_LIT>'] = metrics[self._optimizedMetricLabel]<EOL>jobResults['<STR_LIT>'] = metrics<EOL>jobResults['<STR_LIT>'] = True<EOL>isUpdated = self._jobsDAO.jobSetFieldIfEqual(self._jobID,<EOL>fieldName='<STR_LIT>',<EOL>curValue=jobResultsStr,<EOL>newValue=json.dumps(jobResults))<EOL>if isUpdated:<EOL><INDENT>if prevWasSaved:<EOL><INDENT>self.__deleteOutputCache(prevBest)<EOL>self._jobsDAO.modelUpdateTimestamp(self._modelID)<EOL>self.__deleteModelCheckpoint(prevBest)<EOL>self._jobsDAO.modelUpdateTimestamp(self._modelID)<EOL><DEDENT>self._logger.info("<STR_LIT>", self._modelID)<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.__deleteOutputCache(self._modelID)<EOL>self._jobsDAO.modelUpdateTimestamp(self._modelID)<EOL>self.__deleteModelCheckpoint(self._modelID)<EOL>self._jobsDAO.modelUpdateTimestamp(self._modelID)<EOL>break<EOL><DEDENT><DEDENT>
Check if this is the best model
If so:
  1) Write it's checkpoint
  2) Record this model as the best
  3) Delete the previous best's output cache
Otherwise:
  1) Delete our output cache