def execute(self): def react(data): command = self.commands[self.index - 1] if len(command) != 2: raise fi.exception.UnexpectedError( "Invalid tuple in command list") self.commands[self.index - 1][1](data) self.execute() if self.index == len(self.commands): self.commands = [] self.index = 0 return command = self.commands[self.index][0].split() executable = command[0] arguments = command[1:] # We want to return a deferred def startExecuting(): self.deferred = utils.getProcessOutput(executable, arguments, errortoo=True) self.index += 1 self.deferred.addCallback(react) fi.callLater(startExecuting) return self.deferred
def update(cls): # Schedule credits = [] for client in fi.throttle.model.Client.query.all(): credits.append((client.vpn_ip, client.credit)) allocations = ThrottleApplication.schedule(credits) # Update memory fi.throttle.model.Client.allocate(allocations) # Perform network throttling ThrottleApplication.throttle(allocations) fi.callLater(cls.update)
def execute(self): def react(data): command = self.commands[self.index - 1] if len(command) != 2: raise fi.exception.UnexpectedError("Invalid tuple in command list") self.commands[self.index - 1][1](data) self.execute() if self.index == len(self.commands): self.commands = [] self.index = 0 return command = self.commands[self.index][0].split() executable = command[0] arguments = command[1:] # We want to return a deferred def startExecuting(): self.deferred = utils.getProcessOutput( executable, arguments, errortoo=True ) self.index += 1 self.deferred.addCallback(react) fi.callLater(startExecuting) return self.deferred
class JobClientController(fi.controller.ClientController): def gotRoot(self, root): self.root = root self.askJob() def askJob(self, *args): # Ask for next job fi.logmsg(self.__class__, "Receiving Job") job_d = self.root.callRemote("tellJob", self.ip) job_d.addCallbacks(self.toldJob, self.gotNothing) def toldJob(self, job): """ job:(str, str, serializable) -> None Called after job as been transferred """ # Unpack try: name, module_input, job_input = job except ValueError, e: fi.logmsg(self.__class__, "Invalid job") self.getRoot() return fi.logmsg(self.__class__, "Running %s on %s" % (name, job_input)) # Load module into memory from code module = self.stringToModule(module_input, name) # Run job output = module.__getattribute__(name).getOutput(*job_input) fi.logmsg(self.__class__, "Returning job output") complete = self.root.callRemote( "tellOutput", self.ip, output, ) def askAnother(): complete.addCallbacks(self.askJob, self.gotNothing) fi.callLater(askAnother)
def clientConnectionFailed(self, connector, reason): fi.logmsg(self.__class__, "Connection lost") fi.callLater(connector.connect) fi.logmsg(self.__class__, "Reconnecting...")
def gotRoot(self, root): self.root = root # Start once pathloading to server ThrottleApplication.pathloadSend() fi.callLater(self.askBandwidth)