def main(): # Prepare our context and publisher fedmsg.init(name="bodhi.marat") # Probabilities of us emitting an event on each topic. probs = { 'bodhi': 0.015 * FACTOR, 'fedoratagger': 0.001 * FACTOR, 'pkgdb': 0.001 * FACTOR, 'fas': 0.005 * FACTOR, 'mediawiki': 0.01 * FACTOR, 'git': 0.01 * FACTOR, } # Main loop i = 0 while True: for service, thresh in probs.iteritems(): if random.random() < thresh: print service, thresh fedmsg.send_message( topic='fake_data', msg={'test': "Test data." + str(i)}, modname=service, ) i = i + 1 time.sleep(random.random())
def rank(self, session): _rank = self._rank if self.anonymous: return -1 users = session.query(FASUser)\ .filter(FASUser.username != 'anonymous').all() lookup = sorted(set([u.score for u in users]), reverse=True) rank = lookup.index(self.score) + 1 # If their rank has changed. changed = (rank != _rank) # And it didn't change to last place. We check last_place only to try # and avoid spamming the fedmsg bus. We have a number of users who # have logged in once, and never voted. Everytime a *new* user logs # in and votes once, *all* the users in last place get bumped down # one notch. # No need to spew that to the message bus. is_last = (rank == len(lookup)) if changed: self._rank = rank session.add(self) session.commit() if changed and not is_last: fedmsg.send_message(topic='user.rank.update', msg={ 'user': self, }) return self._rank
def rank(self): _rank = self._rank if self.username == 'anonymous': return -1 users = FASUser.query.filter(FASUser.username != 'anonymous').all() lookup = set([user.total_votes for user in users]) rank = sorted(lookup).index(self.total_votes) + 1 # If their rank has changed. changed = rank != _rank # And it didn't change to last place. We check last_place only to try # and avoid spamming the fedmsg bus. We have a number of users who have # logged in once, and never voted. Everytime a *new* user logs in and # votes once, *all* the users in last place get bumped down one notch. # No need to spew that to the message bus. is_last = rank == len(lookup) if changed: self._rank = rank if changed and not is_last: fedmsg.send_message(topic='user.rank.update', msg={ 'user': self, }) return self._rank
def _log_message(kw, message): msg = {'log': message} if kw['json_input']: msg = fedmsg.json.loads(message) fedmsg.send_message( topic=kw['topic'], msg=msg, modname=kw['modname'], )
def send_message(*args, **kwargs): try: import fedmsg fedmsg.send_message(*args, **kwargs) except Exception, e: warnings.warn(str(e))
def _log_message(kw, message): msg = {"log": message} if kw["json_input"]: msg = fedmsg.json.loads(message) fedmsg.send_message(topic=kw["topic"], msg=msg, modname=kw["modname"])