From 268d2a484873b67c6f399c490522d03a517e7d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Tue, 26 Sep 2023 17:57:36 +0200 Subject: [PATCH] adapt deployment --- .gitlab-ci.yml | 1 + CHANGELOG.md | 7 ++++++ k8s/senpy-deployment.yaml.tmpl | 8 +++++++ senpy/extensions.py | 3 ++- senpy/plugins/__init__.py | 24 ++++++++++++++----- senpy/plugins/emotion/depechemood_plugin.py | 5 +--- .../emotion/wnaffect/emotion-wnaffect.py | 2 +- 7 files changed, 38 insertions(+), 12 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8e5a3d7..6542ef3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,6 +12,7 @@ stages: variables: KUBENS: senpy LATEST_IMAGE: "${HUB_REPO}:${CI_COMMIT_SHORT_SHA}" + SENPY_DATA: "/senpy-data/" # This is configured in the CI job docker: stage: publish diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e733ca..79995a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added * The code of many senpy community plugins have been included by default. However, additional files (e.g., licensed data) and/or installing additional dependencies may be necessary for some plugins. Read each plugin's documentation for more information. +* `--strict` flag, to fail and not start when a +* `optional` attribute in plugins. Optional plugins may fail to load or activate but the server will be started regardless, unless running in strict mode +* Option in shelf plugins to ignore pickling errors +### Removed +* `--only-install`, `--only-test` and `--only-list` flags were removed in favor of `--no-run` + `--install`/`--test`/`--dependencies` +### Changed +* data directory selection logic is slightly modified, and will choose one of the following (in this order): `data_folder` (argument), `$SENPY_DATA` or `$CWD` ## [1.0.6] ### Fixed diff --git a/k8s/senpy-deployment.yaml.tmpl b/k8s/senpy-deployment.yaml.tmpl index c5bb85a..852c73d 100644 --- a/k8s/senpy-deployment.yaml.tmpl +++ b/k8s/senpy-deployment.yaml.tmpl @@ -26,3 +26,11 @@ spec: ports: - name: web containerPort: 5000 + volumeMounts: + - name: senpy-data + mountPath: /senpy-data + subpath: data + volumes: + - name: senpy-data + persistentVolumeClaim: + claimName: pvc-senpy diff --git a/senpy/extensions.py b/senpy/extensions.py index 9e62f0c..f3de477 100644 --- a/senpy/extensions.py +++ b/senpy/extensions.py @@ -365,9 +365,10 @@ class Senpy(object): def _activate(self, plugin): with plugin._lock: if plugin.is_activated: - logger.info(f"Plugin is already activated: {plugin.name}") return try: + logger.info("Activating plugin: {}".format(plugin.name)) + assert plugin._activate() logger.info(f"Plugin activated: {plugin.name}") except Exception as ex: diff --git a/senpy/plugins/__init__.py b/senpy/plugins/__init__.py index f09dd0f..dd1a3b6 100644 --- a/senpy/plugins/__init__.py +++ b/senpy/plugins/__init__.py @@ -122,7 +122,13 @@ class Plugin(with_metaclass(PluginMeta, models.Plugin)): self._directory = os.path.abspath( os.path.dirname(inspect.getfile(self.__class__))) - data_folder = data_folder or os.getcwd() + if not data_folder: + data_folder = os.environ['SENPY_DATA'] + if not data_folder: + data_folder = os.getcwd() + + + data_folder = os.path.abspath(data_folder) subdir = os.path.join(data_folder, self.name) self._data_paths = [ @@ -652,11 +658,17 @@ class ShelfMixin(object): def shelf_file(self, value): self._shelf_file = value - def save(self): - self.log.debug('Saving pickle') - if hasattr(self, '_sh') and self._sh is not None: - with self.open(self.shelf_file, 'wb') as f: - pickle.dump(self._sh, f) + def save(self, ignore_errors=False): + try: + self.log.debug('Saving pickle') + if hasattr(self, '_sh') and self._sh is not None: + with self.open(self.shelf_file, 'wb') as f: + pickle.dump(self._sh, f) + except Exception as ex: + self.log.warning("Could not save shelf state. Check folder permissions for: " + f" {self.shelf_file}. Error: { ex }") + if not ignore_errors: + raise def pfilter(plugins, plugin_type=Analyser, **kwargs): diff --git a/senpy/plugins/emotion/depechemood_plugin.py b/senpy/plugins/emotion/depechemood_plugin.py index aa3948b..4595c56 100644 --- a/senpy/plugins/emotion/depechemood_plugin.py +++ b/senpy/plugins/emotion/depechemood_plugin.py @@ -175,8 +175,5 @@ class DepecheMood(EmotionBox): if __name__ == '__main__': - from senpy.utils import easy, easy_load, easy_test - # sp, app = easy_load() - # for plug in sp.analysis_plugins: - # plug.test() + from senpy.utils import easy_test easy_test(debug=False) diff --git a/senpy/plugins/emotion/wnaffect/emotion-wnaffect.py b/senpy/plugins/emotion/wnaffect/emotion-wnaffect.py index 2e8840e..6e91ddf 100644 --- a/senpy/plugins/emotion/wnaffect/emotion-wnaffect.py +++ b/senpy/plugins/emotion/wnaffect/emotion-wnaffect.py @@ -117,7 +117,7 @@ class WNAffect(EmotionPlugin, ShelfMixin): def deactivate(self, *args, **kwargs): - self.save() + self.save(ignore_errors=True) def _my_preprocessor(self, text):