def change_processors(upload_rate, download_rate): max_processors = get_number_of_processors(upload_rate, download_rate) for engine in Manager.get().get_engines().values(): try: engine.get_queue_manager().restart(max_processors) log.trace('update engine %s processors: %d local, %d remote, %d generic', engine.get_uid(), max_processors[0], max_processors[1], max_processors[2]) except Exception as e: log.error('failed to update engine %s processors: %s', engine.get_uid(), str(e))
def load(self): if self._engine_definitions is None: self._engine_definitions = self._dao.get_engines() in_error = dict() self._engines = dict() for engine in self._engine_definitions: if not engine.engine in self._engine_types: log.warn("Can't find engine %s anymore", engine.engine) if not engine.engine in in_error: in_error[engine.engine] = True self.engineNotFound.emit(engine) self._engines[engine.uid] = self._engine_types[engine.engine]( self, engine, remote_watcher_delay=self.remote_watcher_delay, processors=get_number_of_processors(BaseAutomationClient.get_upload_rate_limit(), BaseAutomationClient.get_download_rate_limit())) self._engines[engine.uid].online.connect(self._force_autoupdate) self.initEngine.emit(self._engines[engine.uid])
def bind_engine(self, engine_type, local_folder, name, binder, starts=True): """Bind a local folder to a remote nuxeo server""" if name is None and hasattr(binder, 'url'): name = self._get_engine_name(binder.url) if hasattr(binder, 'url'): url = binder.url if '#' in url: # Last part of the url is the engine type engine_type = url.split('#')[1] binder.url = url.split('#')[0] log.debug("Engine type has been specified in the url: %s will be used", engine_type) if not self.check_local_folder_available(local_folder): raise FolderAlreadyUsed() if not engine_type in self._engine_types: raise EngineTypeMissing() if self._engines is None: self.load() local_folder = normalized_path(local_folder) if local_folder == self.get_configuration_folder(): # Prevent from binding in the configuration folder raise FolderAlreadyUsed() uid = uuid.uuid1().hex # TODO Check that engine is not inside another or same position engine_def = self._dao.add_engine(engine_type, local_folder, uid, name) try: self._engines[uid] = self._engine_types[engine_type]( self, engine_def, binder=binder, remote_watcher_delay=self.remote_watcher_delay, processors=get_number_of_processors(BaseAutomationClient.get_upload_rate_limit(), BaseAutomationClient.get_download_rate_limit())) self._engine_definitions.append(engine_def) except Exception as e: log.exception(e) if uid in self._engines: del self._engines[uid] self._dao.delete_engine(uid) # TODO Remove the db ? raise e # As new engine was just bound, refresh application update status self.refresh_update_status() if starts: self._engines[uid].start() self.newEngine.emit(self._engines[uid]) return self._engines[uid]