def on_close(self): print "Closing socket for" + self.workerId #abandon current task: TID = wm.W.get_TID(self.workerId) if (TID is not False): print "aborting task: ", TID if (TaskTree[TID].status == 'sap'): TaskTree.add_to_sq(0, TID) else: TaskTree.add_to_q(0, TID) wm.W.complete(self.workerId, False) #NOTE!!! may want to add dynamically changing priority t_amt.delete_amt_hit(self.hitId) wm.W.logout(self.workerId)
def process_approval(self, msg): child = TaskTree[ msg['super_task_id']] #might be incorrectly using supertaskid if (msg['super_approve'] == False ): #rejected, set worker and task idle child.status = 'idle' wm.W.complete(child.wid, False) msg['mode'] = 'idle' msg['WID'] = child.wid send_task(msg) TaskTree.add_to_q(0, child.id) else: #approved child.status = 'approved' if (child.type == 'leaf'): #release leaf to idle & complete child.sapify_leaf() wm.W.complete(child.wid, True) msg['mode'] = 'idle' msg['WID'] = child.wid send_task(msg) #tell parent to try to sap TaskTree.update_sap(child) else: #tell brancher to go super TaskTree.generate_branches( msg, child.id) #generate branches of worker msg['super_mode'] = 'idle' msg['mode'] = 'super' msg['WID'] = child.wid send_task(msg) #if(TaskTree.is_root(child.id) is False): parent = TaskTree[msg['TID']] if (TaskTree.finished_supervision(parent.id)): parent.state = 'sap' #is this too early? we want someone to come along adn sap this now wm.W.complete(parent.wid, True) msg['mode'] = 'idle' else: msg['super_mode'] = 'idle' msg['mode'] = 'super' msg['WID'] = parent.wid send_task(msg)
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
def ready_callback(self, msg): if (TaskTree[msg['TID']].status == 'sap'): mode = 'sap' else: mode = msg['preference'] print "pref:", msg['ready_flag'] if (msg['ready_flag'] == "accept"): # #increase idle time # mins = (msg['time_end']-msg['time_start']).total_seconds() / float(60) # print "adding idle mins:", mins # wm.W.addIdleTime(self.workerId,mins) if (mode == 'sap'): TaskTree[msg['TID']].add_sapwid(self.workerId) else: TaskTree[msg['TID']].add_wid(self.workerId) print "ACCEPTED, mode:", mode msg['mode'] = mode send_task(msg) else: print "declined" msg['mode'] = 'idle' send_task(msg) if (mode == 'sap'): TaskTree.add_to_sq(0, msg['TID']) self.shake_tree_sap() else: TaskTree.add_to_q(0, msg['TID']) self.shake_tree() wm.W.complete(self.workerId, None) print "ready callback" #???