def worker_pong(self): while self.name is None: name = uuid.uuid4().hex if self.set_name(name=name) is not None: self.name = name msg = "[I] Worker name set to {}".format(self.name) Storage.worker_reset_score(name=self.name)
def set_name(self, name=None): if self.name is not None: return (None) if name is None: return (None) if Storage.worker_name_taken(name=name): print("Name={} already taken".format(name)) self.name = None return (None) self.name = name ret = Storage.worker_name_set(name=name) print("Name={} IS NOW OURS".format(name)) return (ret)
def store_new_results(self, results=None): # Step one, validate if self.key is None: return (None) # self.get_key_name_by_assetId() not called? if results is None: return (None) # Step two, check if key already exists if self.key_exists(self.key): return (None) # we are too late? # Step three, add self.key to STATS_{ID}_{PLUGINNAME} redis list Storage.store_results_key_list(plugin_name=self.callerName, assetId=self.assetId, key=self.key) # Step four, store results hash to the appropiate key # STATS_{ID}_{PLUGINNAME}_{DATE} (self.key) Storage.store_results_hash(key=self.key, results=results) # Step five, store results['RESULT'] to STATS_{ID} # which is a redish hash. fieldname = plugin_name # value = results['RESULT'] Storage.update_latest_result(assetId=self.assetId, plugin_name=self.callerName, result=results['RESULT']) Storage.snapshot()
def act_on_results(self, cur=None, prev=None): notify = False # print("ACT_ON_RESULTS(cur={}, prev={})".format(cur,prev)) if cur is None: # should not happen return (None) if prev is None: # might be first run notify = True else: prev = prev[len(prev) - 1] if notify is False: a = int(cur['RESULT']) b = int(prev['RESULT']) if int(cur['RESULT']) != int(prev['RESULT']): print("Change. Will notify.") notify = True if notify is True: pn = self.callerName ret = Storage.append_asset_notification(assetId=self.assetId, plugin_name=pn, datestring=self.datestring, data=cur) return (notify)
def key_exists(self, key): return (Storage.key_exists(key))
def pong(self): # A plugin might need to tell the system it is alive Storage.worker_reset_score(name=self.workername)
def register(self): Storage.register_plugin(plugin_name=self.callerName)
def retrieve_old_results(self, count=10): ret = Storage.retrieve_old_results(assetId=self.assetId, plugin_name=self.callerName, count=count) return (ret)