pluginserver 0.6.2__tar.gz → 0.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pluginserver
3
- Version: 0.6.2
3
+ Version: 0.7.0
4
4
  Summary: Plugin-driven API server
5
5
  Home-page: https://github.com/nicciniamh/pluginserver
6
6
  Author: Nicole Stevens
@@ -30,6 +30,9 @@ class BasePlugin:
30
30
  self._auth_type = 'plugin'
31
31
  self.args = dict(kwargs)
32
32
 
33
+ def terminate_plugin(self):
34
+ pass
35
+
33
36
  def _check_auth(self,data):
34
37
  toktype = 'Undefined'
35
38
  def get_token(data):
@@ -78,7 +81,7 @@ class BasePlugin:
78
81
  if auth_check:
79
82
  result = self.request_handler(**data)
80
83
  code, response = await result if inspect.isawaitable(result) else result
81
- print(f"Got {code} - {response}")
84
+ #print(f"Got {code} - {response}")
82
85
  else:
83
86
  code, response = 403, {'error': 'unauthorized'}
84
87
  if not isinstance(response,web.Response):
@@ -66,6 +66,10 @@ class PluginManager:
66
66
  return
67
67
 
68
68
  # Try to remove the module
69
+ try:
70
+ plugin.terminate_plugin()
71
+ except Exception as e:
72
+ print(f"Exception {type(e)} Unloading plugin - terminate_plugin threw {e}")
69
73
  module_name = plugin.__class__.__module__
70
74
  module_file = os.path.basename(module_name + ".py")
71
75
  print(f"Removing plugin {plugin_id} from module {module_name}")
@@ -18,6 +18,21 @@ import aiohttp_cors
18
18
  from aiohttp import web
19
19
 
20
20
  corsobj = CORS()
21
+
22
+ async def on_shutdown(*args):
23
+ """
24
+ call terminate_plugin for active plugins
25
+ """
26
+ global manager
27
+ print(("Sending plugins the terminate signal"))
28
+ for id, plugin in manager.plugins.items():
29
+ try:
30
+ plugin.terminate_plugin()
31
+ except Exception as e:
32
+ print(f"{type(e)} Exception unloading plugin id {id}")
33
+ print("Waiting for tasks")
34
+ await asyncio.sleep(3)
35
+
21
36
  def main():
22
37
  global manager
23
38
  global globalCfg
@@ -86,7 +101,11 @@ def main():
86
101
  corsobj.setup(app,globalCfg)
87
102
 
88
103
  app.add_routes(routes)
89
- web.run_app(app, host=globalCfg.network.bindto, port=globalCfg.network.port, ssl_context=ssl_ctx)
104
+ app.on_shutdown.append(on_shutdown)
105
+ try:
106
+ web.run_app(app, host=globalCfg.network.bindto, port=globalCfg.network.port, ssl_context=ssl_ctx)
107
+ except KeyboardInterrupt:
108
+ on_shutdown()
90
109
 
91
110
  # --- Auth Helper ---
92
111
  def check_auth(data, config):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pluginserver
3
- Version: 0.6.2
3
+ Version: 0.7.0
4
4
  Summary: Plugin-driven API server
5
5
  Home-page: https://github.com/nicciniamh/pluginserver
6
6
  Author: Nicole Stevens
@@ -4,7 +4,7 @@ from setuptools import setup
4
4
 
5
5
  setup(
6
6
  name='pluginserver',
7
- version='0.6.2',
7
+ version='0.7.0',
8
8
  packages=['plugincore'],
9
9
  include_package_data=True,
10
10
  description='Plugin-driven API server',
File without changes
File without changes
File without changes
File without changes