diff --git a/src/DIRAC/Core/Utilities/MySQL.py b/src/DIRAC/Core/Utilities/MySQL.py index af31450bbd8..91c7c1156e4 100755 --- a/src/DIRAC/Core/Utilities/MySQL.py +++ b/src/DIRAC/Core/Utilities/MySQL.py @@ -756,8 +756,8 @@ def _update(self, cmd, *, conn=None, debug=True): :param debug: print or not the errors - return S_OK with number of updated registers upon success - return S_ERROR upon error + :return: S_OK with number of updated registers upon success. + S_ERROR upon error. """ self.log.debug(f"_update: {self._safeCmd(cmd)}") @@ -791,8 +791,8 @@ def _updatemany(self, cmd, data, *, conn=None, debug=True): :param debug: print or not the errors - return S_OK with number of updated registers upon success - return S_ERROR upon error + :return: S_OK with number of updated registers upon success. + S_ERROR upon error. """ self.log.debug(f"_updatemany: {self._safeCmd(cmd)}") diff --git a/src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py b/src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py index b4310c7f4e1..6be4288562e 100755 --- a/src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py +++ b/src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py @@ -89,36 +89,25 @@ def _get_date(date): + "StatusTime, StatusTimeOrder, StatusSource) VALUES " ) - # if JobID is a list, make a bulk insert - if isinstance(jobID, list): - if isinstance(status, str): - status = [status] * len(jobID) - if isinstance(minorStatus, str): - minorStatus = [minorStatus] * len(jobID) - if isinstance(applicationStatus, str): - applicationStatus = [applicationStatus[:255]] * len(jobID) - if isinstance(_date, datetime.datetime): - _date = [_date] * len(jobID) - - epocs = [] - for dt in _date: - epoc = dt.replace(tzinfo=datetime.timezone.utc).timestamp() - MAGIC_EPOC_NUMBER - epocs.append(epoc) - cmd = cmd + "(%s, %s, %s, %s, %s, %s, %s)" - data = list(zip(jobID, status, minorStatus, applicationStatus, _date, epocs, [source[:32]] * len(jobID))) - return self._updatemany(cmd, data) - else: # else make a single insert - epoc = _date.replace(tzinfo=datetime.timezone.utc).timestamp() - MAGIC_EPOC_NUMBER - cmd = cmd + "(%d,'%s','%s','%s','%s',%f,'%s')" % ( - int(jobID), - status, - minorStatus, - applicationStatus, - str(_date), - epoc, - source[:32], - ) - return self._update(cmd) + if not isinstance(jobID, list): + jobID = [jobID] + + if isinstance(status, str): + status = [status] * len(jobID) + if isinstance(minorStatus, str): + minorStatus = [minorStatus] * len(jobID) + if isinstance(applicationStatus, str): + applicationStatus = [applicationStatus[:255]] * len(jobID) + if isinstance(_date, datetime.datetime): + _date = [_date] * len(jobID) + + epocs = [] + for dt in _date: + epoc = dt.replace(tzinfo=datetime.timezone.utc).timestamp() - MAGIC_EPOC_NUMBER + epocs.append(epoc) + cmd = cmd + "(%s, %s, %s, %s, %s, %s, %s)" + data = list(zip(jobID, status, minorStatus, applicationStatus, _date, epocs, [source[:32]] * len(jobID))) + return self._updatemany(cmd, data) ############################################################################# def getJobLoggingInfo(self, jobID):