Skip to content

Commit

Permalink
docs: better docstrings
Browse files Browse the repository at this point in the history
f
  • Loading branch information
fstagni committed Nov 19, 2024
1 parent 56daf01 commit d834c6c
Show file tree
Hide file tree
Showing 2 changed files with 23 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
49 changes: 19 additions & 30 deletions src/DIRAC/WorkloadManagementSystem/DB/JobLoggingDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d834c6c

Please sign in to comment.