diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2023-09-02 21:48:53 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2023-09-10 19:01:00 +0300 |
| commit | c13734f56e9b01a61cfb66019a71d46c3dfe6f86 (patch) | |
| tree | 155da5a7386a6fabf493640bd9d0eb9aa10313c2 /app/PluginManager.py | |
| parent | 4745449cf847f27c3cbbca5cef2f1d9d02103692 (diff) | |
Add tinydb
Diffstat (limited to 'app/PluginManager.py')
| -rw-r--r-- | app/PluginManager.py | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/app/PluginManager.py b/app/PluginManager.py index 3ec9d44..da85428 100644 --- a/app/PluginManager.py +++ b/app/PluginManager.py @@ -21,8 +21,6 @@ class PluginManager: plugin_class = module.Plugin self._plugins[plugin_name] = plugin_class - # TODO instead of propagating procedurally, - # insert data into an next_node_id-identified input queue in tinydb def propagate(self, id: str, items: list[Item]): next_nodes: list[str] if id not in self.config.graph: @@ -31,14 +29,14 @@ class PluginManager: next_nodes = self.config.graph[id] for next_node_id in next_nodes: - self.run_plugin_job(next_node_id, items) + self.run_plugin_job(next_node_id, id, items) - def run_plugin_job(self, id: str, items: list[Item] = []): + def run_plugin_job(self, id: str, source_id: str | None, items: list[Item] = []): if not memory_state.running: return plugin: PluginInterface = self.plugin_instances[id] - ret_items: list[Item] = plugin.process(items) + ret_items: list[Item] = plugin.process(source_id, items) self.propagate(id, ret_items) def build_plugin_instances(self): @@ -47,20 +45,14 @@ class PluginManager: params: dict[str, str] = self.config.plugins[id] plugin_name = get_param("plugin", params) - trigger_type = get_param("trigger_type", params) + schedule_expr: str | None = params.get("schedule_expr", None) if plugin_name not in self._plugins: self.load_plugin(plugin_name) - match trigger_type: - case "schedule": - schedule_expr = get_param("schedule_expr", params) - job: schedule.Job = eval(schedule_expr, {"schedule": schedule}) - job.do(self.run_plugin_job, id) # type: ignore - case "input_change": - pass - case _: - raise Exception("unknown trigger_type: " + trigger_type) + if schedule_expr is not None: + job: schedule.Job = eval(schedule_expr, {"schedule": schedule}) + job.do(self.run_plugin_job, id, None) # type: ignore PluginClass: Any = self._plugins[plugin_name] plugin: PluginInterface = PluginClass(id=id, params=params) |
