File indexing completed on 2026-04-10 08:39:06
0001 """
0002 worker specification
0003
0004 """
0005
0006 import datetime
0007
0008
0009 class HarvesterMetricsSpec(object):
0010
0011 _attributes = ("harvester_ID", "creation_time", "harvester_host", "metrics")
0012
0013 __slots__ = _attributes + ("_changedAttrs",)
0014
0015 _zeroAttrs = ()
0016
0017
0018 def __init__(self):
0019
0020 for attr in self._attributes:
0021 object.__setattr__(self, attr, None)
0022
0023 object.__setattr__(self, "_changedAttrs", {})
0024
0025
0026 def __setattr__(self, name, value):
0027 oldVal = getattr(self, name)
0028
0029 if isinstance(value, str) and value.startswith("datetime/"):
0030 value = datetime.datetime.strptime(value.split("/")[-1], "%Y-%m-%d %H:%M:%S.%f")
0031 object.__setattr__(self, name, value)
0032
0033 if oldVal != value:
0034 self._changedAttrs[name] = value
0035
0036
0037 def resetChangedList(self):
0038 self._oldPandaID = self.PandaID
0039 object.__setattr__(self, "_changedAttrs", {})
0040
0041
0042 def valuesMap(self, onlyChanged=False):
0043 ret = {}
0044 for attr in self._attributes:
0045 if onlyChanged and attr not in self._changedAttrs:
0046 continue
0047 val = getattr(self, attr)
0048 if val is None:
0049 if attr in self._zeroAttrs:
0050 val = 0
0051 ret[f":{attr}"] = val
0052 return ret
0053
0054
0055 def pack(self, values):
0056 for i in range(len(self._attributes)):
0057 attr = self._attributes[i]
0058 val = values[i]
0059 object.__setattr__(self, attr, val)
0060
0061
0062 def columnNames(cls):
0063 ret = ""
0064 for attr in cls._attributes:
0065 ret += f"{attr},"
0066 ret = ret[:-1]
0067 return ret
0068
0069 columnNames = classmethod(columnNames)
0070
0071
0072 def bindValuesExpression(cls):
0073 from pandaserver.config import panda_config
0074
0075 ret = "VALUES("
0076 for attr in cls._attributes:
0077 ret += f":{attr},"
0078 ret = ret[:-1]
0079 ret += ")"
0080 return ret
0081
0082 bindValuesExpression = classmethod(bindValuesExpression)
0083
0084
0085 def bindUpdateChangesExpression(self):
0086 ret = ""
0087 for attr in self._attributes:
0088 if attr not in self._changedAttrs:
0089 continue
0090 ret += "{0}=:{0},".format(attr)
0091 ret = ret[:-1]
0092 return ret