def test_callbacks(self): done = [False] method = Mock() req = AsyncRequest(method) def success(*_): done[0] = True def error(*_): done[0] = True done[0] = False method.called = False async_run(req, success, error) time.sleep(1) assert method.called done[0] = False method.called = False async_run(req) time.sleep(1) assert method.called
def run_test_task(self, t_dict): if self.task_tester is None: request = AsyncRequest(self._run_test_task, t_dict) async_run(request) return True if self.rpc_publisher: self.rpc_publisher.publish(Task.evt_task_test_status, TaskTestStatus.error, u"Another test is running") return False
def get_balance(self): if self.use_transaction_system(): req = AsyncRequest(self.transaction_system.get_balance) b, ab, d = yield async_run(req) if b is not None: returnValue((unicode(b), unicode(ab), unicode(d))) returnValue((None, None, None))
def __send_result_hash(self, res): task_result_manager = self.task_manager.task_result_manager resource_manager = task_result_manager.resource_manager client_options = resource_manager.build_client_options( self.task_server.get_key_id()) subtask_id = res.subtask_id secret = task_result_manager.gen_secret() def success(result): result_path, result_hash = result logger.debug("Task session: sending task result hash: %r (%r)", result_path, result_hash) self.send( message.MessageTaskResultHash(subtask_id=subtask_id, multihash=result_hash, secret=secret, options=client_options)) def error(exc): logger.error( "Couldn't create a task result package for subtask %r: %r", res.subtask_id, exc) if isinstance(exc, EnvironmentError): self.task_server.retry_sending_task_result(subtask_id) else: self.send_task_failure(subtask_id, '{}'.format(exc)) self.task_server.task_result_sent(subtask_id) self.dropped() request = AsyncRequest(task_result_manager.create, self.task_server.node, res, client_options=client_options, key_or_secret=secret) return async_run(request, success=success, error=error)
def get_external_address(self): request = AsyncRequest(get_external_address, self.listen_port) return async_run(request)
def _run_async(self): return async_run(AsyncRequest(self._run), error=self._exceptionHandler)
def package_downloaded(*args, **kwargs): request = AsyncRequest(self.extract, file_path, output_dir=output_dir, key_or_secret=key_or_secret) async_run(request, package_extracted, error)
def add_task(self, files, task_id, client=None, client_options=None): request = AsyncRequest(self._add_task, files, task_id, client=client, client_options=client_options) return async_run(request)