def reroute_to(connector, frequency, vector): for dest, freq in frequency.items(): if freq.next(): new_vector = vector.copy() send_vector(connector.cnx["orchester_out"], new_vector, "INIT", dict( type = dest, next = dest, seq = 0, job_id = dest, task_id = next_tick() ) )
def cpu_clock(connector,_5, vector): #try: #sleep(float(_5) * .1 ) new_vector = vector try: send_vector(connector.cnx["orchester_out"], new_vector, "INIT", dict( type = "master", next = "master", seq = 0, job_id = "clock", task_id = next_tick()) ) sleep( (float(_5) ** 2 ) * .01 ) except Exception as e: connector.log.exception(e) raise Exception("AARG %r" % e)
def reschedule(scheduler, vector, socket): """push a job on socket at rescheduled interval rescheduler si task_id qui est dans what appartient aux taches active TOFIX loses one job a day w 300 sec interval TODO find the hidden monotonic time function """ try: next_delay = when = int(task.get("arg",{}).get("_every", DELAY)) next_delay -= ( int(m_time()) % when) job_id = task["type"], task["task_id"] = str(int(task["task_id"]) + 1) task["seq"] = "0" send_vector(socket,vector) Timer(next_delay, reschedule, (ticker, task, socket ) ).start() D('job %r rescheduled' % job_id) except Exception as e: logging.exception("ARGGGGGG %r" % e)
def test_consistency(self): s1, s2 = self.create_bound_pair(zmq.PUSH,zmq.PULL) sleep(.1) msg = dict( job_id=1, task_id=1, seq = 1, where = "here", next = "generation", wid = 2, event = "whatever", state = "nawak", step = "this", pid = 123, arg = dict( a = 1, b = 2), type = "test", ) send_vector(s1, msg) v = parse_event(s2) self.assertEqual(v["seq"], "2") for k,v in msg.items(): if "seq" != k: self.assertEqual(v, msg[k])
def reschedule(scheduler, vector, socket): """push a job on socket at rescheduled interval rescheduler si task_id qui est dans what appartient aux taches active """ global smoothing_factor try: next_delay = DELAY next_delay -= ( float(time()) % DELAY) #log.info("next event in %r" % next_delay) job_id = vector["type"], incr_task_id(vector) vector["seq"] = "0" send_vector(socket,vector) Timer(next_delay, reschedule, (ticker, vector, socket ) ).start() D('job %r rescheduled' % job_id) except Exception as e: log.error("ARGGGGGG %r" % e) log.exception(e) sleep(1)
ticker = sched.scheduler(time, sleep) CFG, L_CFG, ID = construct_info(sys.argv, "master") cnx = get_connection(CFG, L_CFG) task_id = int(time()) ev = { "seq":0, "type" : "cpu","when" : 0, "event" : "INIT", "next":"orchester", "job_id": "0", "task_id":0,"seq":0, "arg" : {"load" : 0, "5min" : 0}, "where" : "localhost", "step" :"master", "wid":"0", "pid":str(os.getpid()),"retry":2 } print ev ### BUG in construct_info send_vector( cnx["orchester_out"], ev) while True: sleep(1) def reschedule(scheduler, vector, socket): """push a job on socket at rescheduled interval rescheduler si task_id qui est dans what appartient aux taches active TOFIX loses one job a day w 300 sec interval TODO find the hidden monotonic time function """ try: next_delay = when = int(task.get("arg",{}).get("_every", DELAY)) next_delay -= ( int(m_time()) % when) job_id = task["type"], task["task_id"] = str(int(task["task_id"]) + 1)
def event_listener(CNX, config): """Processlet responsible for routing and reacting on status change""" D("event listener") cnx = CNX poller = zmq.Poller() out_sign = cnx["_context"].socket(zmq.PUB) out_sign.connect(CONFIG["cnx"]["SUB_orchester_master"] %config) other_in = cnx["orchester_in"] master_sox = cnx["master"] master_sox.setsockopt_string(zmq.SUBSCRIBE,unicode(LOCAL_INFO["where"])) poller.register(master_sox, zmq.POLLIN) poller.register(other_in, zmq.POLLIN) cpt=0 now = time() while True: if not(cpt%1000): print "%.1f msg/sec %.2f" % (time(), 1.0*cpt/(time() - now)) cpt = 0 now = time() cpt+=1 new={} ready_sox = dict(poller.poll()) if other_in in ready_sox and ready_sox[other_in] == zmq.POLLIN: new = parse_event(other_in) D("rcv from OTHER %s" % _f(new)) elif master_sox in ready_sox and ready_sox[master_sox] == zmq.POLLIN: new = parse_event(master_sox) D("rcv from MASTER %s" % _f(new)) if new == {}: continue if new["where"] != LOCAL_INFO["where"]: log.info("NOT FOR ME Iam %s not %s " % (new["where"], LOCAL_INFO["where"])) #D("*****") continue try: # only one message at a time can be treated not even sure I need it task_id = new["task_id"] job_id = new["job_id"] D("RCV%r"%_f(new)) if new["event"] in { "INIT", "BOUNCE"}: re_send_vector(cnx["tracker_out"],new, "ACK", dict( pid = config["pid"])) new["task_id"] = str(task_id.isdigit() and (int(task_id)+1) or task_id) new["state"] = "do I use that?" new["retry"] = "0" new["step"] ="orchester" new["event"] = "INIT" new["next"] = new["type"] D("initing to %s" % _f(new)) D("sending to %r" % cnx[new["type"]]) send_vector(cnx[new["next"]], new) #log.warning("gup %r %r" % (monitor, new)) re_send_vector(cnx["tracker_out"],new, "SEND", dict( pid = config["pid"])) #send_vector(monitor, new) else: log.warning("unknown message caught %r" % _f(new)) if "PROPAGATE" == new["event"]: D("skipping PROPAGATE for %s" % _f(new)) except Exception as e: log.exception("MON %s" % e)
while message and not abort: if "q" == message: break if "r" == _what: recv = True elif _what: message = _what abort = True else: message = "".join(iter(lambda: raw_input("%s >" % _to), "ç")) try: if recv: cpt = 0 while True: print "waiting ..." print fast_parse_vector(client) print "RECEVIED" print (" " * cpt) + ["\\", "-", "/", "|"][cpt % 4] cpt += 1 else: print ("SENT %s" % loads(message)) print "\n" print client.socket_type send_vector(client, loads(message)) except Exception as e: print (repr(e)) D("sent %r" % message) write_history_file(HIST)