Skip to content

Commit 320ecd4

Browse files
authored
Merge pull request #7300 from chaen/utcTimeStamp
Fix race condition in the JobLoggingDB
2 parents e7d0d29 + 9ec7ccf commit 320ecd4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ def addLoggingRecord(
7171
except Exception:
7272
self.log.exception("Exception while date evaluation")
7373
_date = datetime.datetime.utcnow()
74-
epoc = time.mktime(_date.timetuple()) + _date.microsecond / 1000000.0 - MAGIC_EPOC_NUMBER
74+
75+
# We need to specify that timezone is UTC because otherwise timestamp
76+
# assumes local time while we mean UTC.
77+
epoc = _date.replace(tzinfo=datetime.timezone.utc).timestamp() - MAGIC_EPOC_NUMBER
7578

7679
cmd = (
7780
"INSERT INTO LoggingInfo (JobId, Status, MinorStatus, ApplicationStatus, "
@@ -138,7 +141,7 @@ def getWMSTimeStamps(self, jobID):
138141
# self.log.debug('getWMSTimeStamps: Retrieving Timestamps for Job %d' % int(jobID))
139142

140143
result = {}
141-
cmd = "SELECT Status,StatusTimeOrder FROM LoggingInfo WHERE JobID=%d" % int(jobID)
144+
cmd = "SELECT Status,StatusTimeOrder FROM LoggingInfo WHERE JobID=%d ORDER BY StatusTimeOrder" % int(jobID)
142145
resCmd = self._query(cmd)
143146
if not resCmd["OK"]:
144147
return resCmd

0 commit comments

Comments
 (0)