def package_downloaded(*args, **kwargs): request = golem_async.AsyncRequest( self.extract, file_path, output_dir=output_dir, key_or_secret=key_or_secret, ) golem_async.async_run(request, package_extracted, error)
def _handle_remote_rpc_provider_failure(self): from golem.core import golem_async log.warning('GETH: reconnecting to another provider') self.provider_proxy.provider = None request = golem_async.AsyncRequest(self.start) golem_async.async_run(request).addErrback( lambda err: self._handle_remote_rpc_provider_failure())
def create_resource_package(self, files, task_id) -> Deferred: resource_dir = self.resource_manager.storage.get_dir(task_id) package_path = os.path.join(resource_dir, task_id) request = golem_async.AsyncRequest( self.packager.create, package_path, files, ) return golem_async.async_run(request)
def _setup_client(self, *_) -> None: if not self._keys_auth: self._error("KeysAuth is not available") return from golem.tools.talkback import enable_sentry_logger enable_sentry_logger(self._use_talkback) self.client = self._client_factory(self._keys_auth) self._reactor.addSystemEventTrigger("before", "shutdown", self.client.quit) self.client.set_rpc_publisher(self._rpc_publisher) golem_async.async_run( golem_async.AsyncRequest(self._run), error=self._error('Cannot start the client'), )
def _extract_task_resources(self, resource, task_id): resource_dir = self.resource_manager.storage.get_dir(task_id) ctk = self.client.task_server.task_manager.comp_task_keeper def extract_packages(package_files): package_paths = [] for package_file in package_files: package_path = os.path.join(resource_dir, package_file) package_paths.append(package_path) logger.info('Extracting task resource: %r', package_path) self.packager.extract(package_path, resource_dir) ctk.add_package_paths(task_id, package_paths) async_req = golem_async.AsyncRequest(extract_packages, resource[1]) golem_async.async_run(async_req).addCallbacks( lambda _: self.client.task_resource_collected(task_id, unpack_delta=False), lambda e: self._download_error(e, resource, task_id))
def test_callbacks(self): method = Mock() request = golem_async.AsyncRequest(method) result = Mock(value=None) def success(*_): result.value = True def error(*_): result.value = False golem_async.async_run(request) time.sleep(0.5) assert method.call_count == 1 assert result.value is None golem_async.async_run(request, success) time.sleep(0.5) assert method.call_count == 2 assert result.value is True method.side_effect = Exception golem_async.async_run(request, success, error) time.sleep(0.5) assert method.call_count == 3 assert result.value is False
def do_maintenance(self): """Updates information on unsupported task reasons and other related task statistics by consuming tasks and support statuses scheduled for processing by add_task() and add_support_status() functions. Optimizes internal structures and, if needed, writes the entire structure to a file. """ input_tasks, self._input_tasks = self._input_tasks, [] input_statuses, self._input_statuses = self._input_statuses, [] with self._archive_lock: ntasks_to_take = self._max_tasks - len(self._archive.tasks) if ntasks_to_take < len(input_tasks): log.warning("Maximum number of current tasks exceeded.") input_tasks = input_tasks[:ntasks_to_take] for tsk in input_tasks: self._archive.tasks[tsk.uuid] = tsk for (uuid, status) in input_statuses: if uuid in self._archive.tasks: if UnsupportReason.REQUESTOR_TRUST in status.desc: self._archive.tasks[uuid].requesting_trust = \ status.desc[UnsupportReason.REQUESTOR_TRUST] self._archive.tasks[uuid].unsupport_reasons = \ list(status.desc.keys()) cur_time = get_timestamp_utc() for tsk in list(self._archive.tasks.values()): if cur_time > tsk.deadline: self._merge_to_interval(tsk) del self._archive.tasks[tsk.uuid] self._purge_old_intervals() if self._dump_file: request = golem_async.AsyncRequest(self._dump_archive) golem_async.async_run( request, None, lambda e: log.info("Dumping archive failed: %s", e), )
def dump(self): if not self.persist: return golem_async.async_run(golem_async.AsyncRequest(self._dump_tasks))
def _run_async(self): return golem_async.async_run( golem_async.AsyncRequest(self._run), error=self._exceptionHandler, )