Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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()
Example #4
0
    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)
Example #5
0
 def key_exists(self, key):
     return (Storage.key_exists(key))
Example #6
0
 def pong(self):
     # A plugin might need to tell the system it is alive
     Storage.worker_reset_score(name=self.workername)
Example #7
0
 def register(self):
     Storage.register_plugin(plugin_name=self.callerName)
Example #8
0
 def retrieve_old_results(self, count=10):
     ret = Storage.retrieve_old_results(assetId=self.assetId,
                                        plugin_name=self.callerName,
                                        count=count)
     return (ret)