From 864466171c07d0420ae7ede2ae81e8544df23105 Mon Sep 17 00:00:00 2001 From: chaen Date: Wed, 22 Nov 2023 15:23:18 +0100 Subject: [PATCH] sweep: #7300 Fix race condition in the JobLoggingDB --- src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py b/src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py index 2041e950277..51fd0092e25 100755 --- a/src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py +++ b/src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py @@ -62,7 +62,10 @@ def addLoggingRecord( except Exception: self.log.exception("Exception while date evaluation") _date = datetime.datetime.utcnow() - epoc = time.mktime(_date.timetuple()) + _date.microsecond / 1000000.0 - MAGIC_EPOC_NUMBER + + # We need to specify that timezone is UTC because otherwise timestamp + # assumes local time while we mean UTC. + epoc = _date.replace(tzinfo=datetime.timezone.utc).timestamp() - MAGIC_EPOC_NUMBER cmd = ( "INSERT INTO LoggingInfo (JobId, Status, MinorStatus, ApplicationStatus, " @@ -129,7 +132,7 @@ def getWMSTimeStamps(self, jobID): # self.log.debug('getWMSTimeStamps: Retrieving Timestamps for Job %d' % int(jobID)) result = {} - cmd = "SELECT Status,StatusTimeOrder FROM LoggingInfo WHERE JobID=%d" % int(jobID) + cmd = "SELECT Status,StatusTimeOrder FROM LoggingInfo WHERE JobID=%d ORDER BY StatusTimeOrder" % int(jobID) resCmd = self._query(cmd) if not resCmd["OK"]: return resCmd