30 lines
866 B
Python
30 lines
866 B
Python
"""Discover and run event adapters without editing the pipeline core."""
|
|
import importlib
|
|
import pkgutil
|
|
from pathlib import Path
|
|
|
|
from .base import Adapter
|
|
|
|
|
|
def load_adapters():
|
|
adapters = []
|
|
pkg_dir = Path(__file__).resolve().parent
|
|
for mod in sorted(pkgutil.iter_modules([str(pkg_dir)])):
|
|
if mod.name in ("base", "registry") or mod.name.startswith("_"):
|
|
continue
|
|
m = importlib.import_module("adapter_plugins." + mod.name)
|
|
for obj in vars(m).values():
|
|
if isinstance(obj, type) and issubclass(obj, Adapter) and obj is not Adapter:
|
|
adapters.append(obj())
|
|
return adapters
|
|
|
|
|
|
def run_all(conn):
|
|
out = {}
|
|
for a in load_adapters():
|
|
try:
|
|
out[a.name] = a.poll(conn)
|
|
except Exception as e:
|
|
out[a.name] = "error:%s" % str(e)[:120]
|
|
return out
|