def select_callback(self, msg): wm.W.set_type(self.workerId, msg['preference']) self.preference = msg['preference'] self.send_msg(tms.new_msg(mode="idle", WID=self.workerId, TID="")) #fill in params more completely print "select callback shake starts" len = TaskTree.get_q_len() # Tasks available ? self.shake_tree() # Look to match more work and tasks self.shake_tree_sap() print "select callback shake returns"
def shake_tree(self, mode=None): elem = TaskTree.get_q_len() for i in range(1, elem + 1): # get a task to assign tq = TaskTree.get_q_elem() # get a task to assign if (TaskTree[tq[1]].status != "idle"): continue print 'shake_tree: NewQlen=' + str(elem) + 'Task got is ' + str(tq) if (TaskTree[tq[1]].type == 'leaf'): wid = wm.W.assign('leaf', tq[1]) is_leafer = True else: wid = wm.W.assign('branch', tq[1]) is_leafer = False if (wid): ws = wm.W.get_socket(wid) # ws.write_message('Shruthi-try') if (is_leafer): msg = ws.fill_msg_wsh(tq[1], 'leaf') else: msg = ws.fill_msg_wsh(tq[1], 'branch') print 'Sending a msg to show task ' + str( tq[1]) + 'to worker ' + wid #print 'Socket of wid is ' + str(ws.workerId) #important step for sending ready msgs: #hide the mode of the message in preference to know #what content to preview to worker. msg['preference'] = msg['mode'] msg['mode'] = "ready" send_task(msg) #todo:msg = ws.fill_msg_wsh(tq[1]) else: print 'Warning - no workers' TaskTree.add_to_q(tq[0], tq[1]) # Put the task back in the queue