Commit 3ffc882e authored by kaiyou's avatar kaiyou

Add a jinja template renderer for notifiers

parent b22ac975
...@@ -42,7 +42,7 @@ class Scheduler(object): ...@@ -42,7 +42,7 @@ class Scheduler(object):
state = json.loads(value) if value else {"status": True, "count": 0} state = json.loads(value) if value else {"status": True, "count": 0}
state.update( state.update(
count=state["count"] + 1 if status == state["status"] else 0, count=state["count"] + 1 if status == state["status"] else 0,
status=status, result=result name=name, status=status, result=result
) )
self.storage.set(name, json.dumps(state)) self.storage.set(name, json.dumps(state))
state.update(**context) state.update(**context)
......
import importlib import importlib
import jinja2
def resolve(function, cache={}): def resolve(function, cache={}):
...@@ -8,3 +9,7 @@ def resolve(function, cache={}): ...@@ -8,3 +9,7 @@ def resolve(function, cache={}):
module, name = function.rsplit(".", 1) module, name = function.rsplit(".", 1)
cache[function] = getattr(importlib.import_module(module), name) cache[function] = getattr(importlib.import_module(module), name)
return cache[function] return cache[function]
def render(template, data):
return jinja2.Template(template).render(**data)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment