Skip to content

Commit

Permalink
docs: better docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
fstagni committed Nov 20, 2024
1 parent 56daf01 commit cd14009
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
8 changes: 4 additions & 4 deletions src/DIRAC/Core/Utilities/MySQL.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)}")
Expand Down Expand Up @@ -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)}")
Expand Down
51 changes: 21 additions & 30 deletions src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,36 +89,27 @@ 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), strict=True)
)
return self._updatemany(cmd, data)

#############################################################################
def getJobLoggingInfo(self, jobID):
Expand Down

0 comments on commit cd14009

Please sign in to comment.