def join(self, max_wait_seconds=None): """ @type max_wait_seconds: float, None """ try: if self.tasksubscription is None: raise TaskException("task not started") rs = RedisServer("crypto_taskworker", verbose=self.verbose) try: if max_wait_seconds: start = time.time() runtime = time.time() - start while runtime < max_wait_seconds: if self.tasksubscription.is_alive(): time.sleep(0.1) rs.event_emit("runtasks", self.get_serverconfig().get_namespace()) runtime = time.time() - start else: break if runtime > max_wait_seconds: raise RedisEventWaitTimeout() else: while self.tasksubscription.is_alive(): time.sleep(0.1) rs.event_emit("runtasks", self.get_serverconfig().get_namespace()) except RedisEventWaitTimeout: object_name = self.human_object_name(self.object_id) raise TaskTimeOut(str(object_name) + " timed out") if self.m_task_exception is not None: if len(self.m_task_exception) > 0: major_info = console_saved_exception(self.m_task_exception, False) excclass = str(major_info[0]).strip().split(".") if len(excclass) > 1: excclass = excclass[1].strip("'>") exc = TaskExecuteException(major_info) major_info[0] = excclass exc.verbose = self.verbose globalvars = globals() if excclass in globalvars: raise globalvars[excclass]("\n\n" + "\n".join(major_info)) else: raise exc return True finally: if self.object_id is not None: self.delete(delete_from_datastore=False)
def start(self, *argc): """ @param argc: @type argc: """ if self.verbose: console("task_start", self.object_id, color="magenta") if not self.m_crypto_user_object_id: raise TaskException("start: no crypto_user_object_id set") self.save_callable(argc) rs = RedisServer("crypto_taskworker", verbose=self.verbose) def taskdone(taskid): """ @type taskid: str """ if taskid is None: return if self.verbose: console("taskdone", taskid, source_code_link(), color="magenta") if taskid == self.object_id: self.load() self.tasksubscription = rs.event_subscribe("taskdone:" + str(self.object_id), taskdone) rs.list_push("tasks", self.object_id) rs.event_emit("runtasks", self.get_serverconfig().get_namespace())
def setUp(self): """ setUp """ cleanup_tempfiles() os.system("rm -Rf testdata/test") self.db_name = "rabshakeh" server = "http://127.0.01:8000/" self.options_d = {"basedir": "/Users/rabshakeh/workspace/cryptobox/cryptobox_app/source/commands/testdata", "dir": "/Users/rabshakeh/workspace/cryptobox/cryptobox_app/source/commands/testdata/test", "encrypt": True, "remove": False, "username": "******", "password": "******", "cryptobox": self.db_name, "clear": False, "sync": False, "server": server, "numdownloadthreads": 12} self.cboptions = Dict2Obj(self.options_d) rs = RedisServer("mutex") rs.flush_namespace() self.cbmemory = Memory() self.cbmemory.set("cryptobox_folder", self.cboptions.dir) # self.reset_cb_db_clean() # self.cbmemory = authorize_user(self.cbmemory, self.cboptions, force=True) self.do_wait_for_tasks = True self.testfile_sizes = ["2MB.zip", "200MB.zip", "100MB.zip", "20MB.zip", "5MB.zip", "50MB.zip"] for tfn in self.testfile_sizes: if not os.path.exists(os.path.join("testdata", tfn)): self.make_testfile(tfn, int(tfn.replace("MB.zip", ""))) self.remove_temp_files = False