Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-10 08:39:07

0001 """
0002 worker specification
0003 
0004 """
0005 
0006 import datetime
0007 
0008 
0009 class WorkerSpec(object):
0010     # attributes
0011     _attributes = (
0012         "harvesterID",
0013         "workerID",
0014         "batchID",
0015         "queueName",
0016         "status",
0017         "computingSite",
0018         "nCore",
0019         "nodeID",
0020         "submitTime",
0021         "startTime",
0022         "endTime",
0023         "lastUpdate",
0024         "stdOut",
0025         "stdErr",
0026         "batchLog",
0027         "jdl",
0028         "resourceType",
0029         "nativeExitCode",
0030         "nativeStatus",
0031         "diagMessage",
0032         "nJobs",
0033         "computingElement",
0034         "submissionHost",
0035         "harvesterHost",
0036         "errorCode",
0037         "jobType",
0038         "minRamCount",
0039     )
0040     # slots
0041     __slots__ = _attributes + ("_changedAttrs",)
0042     # attributes which have 0 by default
0043     _zeroAttrs = ()
0044     # catchall resouce type
0045     RT_catchall = "ANY"
0046 
0047     # constructor
0048     def __init__(self):
0049         # install attributes
0050         for attr in self._attributes:
0051             object.__setattr__(self, attr, None)
0052         # map of changed attributes
0053         object.__setattr__(self, "_changedAttrs", {})
0054 
0055     # override __setattr__ to collect the changed attributes
0056     def __setattr__(self, name, value):
0057         oldVal = getattr(self, name)
0058         # convert string to datetime
0059         if isinstance(value, str) and value.startswith("datetime/"):
0060             value = datetime.datetime.strptime(value.split("/")[-1], "%Y-%m-%d %H:%M:%S.%f")
0061         object.__setattr__(self, name, value)
0062         # collect changed attributes
0063         if oldVal != value:
0064             self._changedAttrs[name] = value
0065 
0066     # reset changed attribute list
0067     def resetChangedList(self):
0068         self._oldPandaID = self.PandaID
0069         object.__setattr__(self, "_changedAttrs", {})
0070 
0071     # return map of values
0072     def valuesMap(self, onlyChanged=False):
0073         ret = {}
0074         for attr in self._attributes:
0075             if onlyChanged and attr not in self._changedAttrs:
0076                 continue
0077             val = getattr(self, attr)
0078             if val is None:
0079                 if attr in self._zeroAttrs:
0080                     val = 0
0081             ret[f":{attr}"] = val
0082         return ret
0083 
0084     # pack tuple into FileSpec
0085     def pack(self, values):
0086         for i in range(len(self._attributes)):
0087             attr = self._attributes[i]
0088             val = values[i]
0089             object.__setattr__(self, attr, val)
0090 
0091     # return column names for INSERT
0092     def columnNames(cls, prefix=None):
0093         ret = ""
0094         for attr in cls._attributes:
0095             if prefix is not None:
0096                 ret += f"{prefix}."
0097             ret += f"{attr},"
0098         ret = ret[:-1]
0099         return ret
0100 
0101     columnNames = classmethod(columnNames)
0102 
0103     # return expression of bind variables for INSERT
0104     def bindValuesExpression(cls):
0105         from pandaserver.config import panda_config
0106 
0107         ret = "VALUES("
0108         for attr in cls._attributes:
0109             ret += f":{attr},"
0110         ret = ret[:-1]
0111         ret += ")"
0112         return ret
0113 
0114     bindValuesExpression = classmethod(bindValuesExpression)
0115 
0116     # return an expression of bind variables for UPDATE to update only changed attributes
0117     def bindUpdateChangesExpression(self):
0118         ret = ""
0119         for attr in self._attributes:
0120             if attr not in self._changedAttrs:
0121                 continue
0122             ret += "{0}=:{0},".format(attr)
0123         ret = ret[:-1]
0124         return ret
0125 
0126     # return state values to be pickled
0127     def __getstate__(self):
0128         state = []
0129         for attr in self._attributes:
0130             val = getattr(self, attr)
0131             state.append(val)
0132         state.append(self._changedAttrs)
0133         return state
0134 
0135     # restore state from the unpickled state values
0136     def __setstate__(self, state):
0137         i = 0
0138         for attr in self._attributes:
0139             if i >= len(state) - 1:
0140                 break
0141             object.__setattr__(self, attr, state[i])
0142             i += 1
0143         object.__setattr__(self, "_changedAttrs", state[-1])