1
0
Fork 0

Invert @ensure_initialized and @action annotations.

Otherwise, we won't be able to access the wrapped function from the
inspection logic.
This commit is contained in:
Fabio Manganiello 2023-10-12 02:57:20 +02:00
parent 8ef67012ed
commit e382ad7650
2 changed files with 11 additions and 11 deletions
platypush
backend/http/webapp/src/components/panels/Execute
plugins/variable

View file

@ -113,6 +113,7 @@ import Utils from "@/Utils"
export default { export default {
name: "Execute", name: "Execute",
mixins: [Utils],
components: { components: {
ActionArgs, ActionArgs,
ActionDoc, ActionDoc,
@ -123,7 +124,6 @@ export default {
Tab, Tab,
Tabs, Tabs,
}, },
mixins: [Utils],
data() { data() {
return { return {

View file

@ -28,7 +28,7 @@ def ensure_initialized(f: Callable[..., Any]):
self._initialized.set() self._initialized.set()
with self._db.get_session() as session: with self._db.get_session() as session:
self._db_vars.update( self._db_vars.update(
{ # type: ignore {
str(var.name): var.value str(var.name): var.value
for var in session.query(Variable).all() for var in session.query(Variable).all()
} }
@ -57,8 +57,8 @@ class VariablePlugin(Plugin, EntityManager):
self._init_lock = RLock() self._init_lock = RLock()
""" Lock for the _db_vars map initialization. """ """ Lock for the _db_vars map initialization. """
@action
@ensure_initialized @ensure_initialized
@action
def get(self, name: Optional[str] = None, default_value=None): def get(self, name: Optional[str] = None, default_value=None):
""" """
Get the value of a variable by name from the local db. Get the value of a variable by name from the local db.
@ -74,8 +74,8 @@ class VariablePlugin(Plugin, EntityManager):
else self.status().output else self.status().output
) )
@action
@ensure_initialized @ensure_initialized
@action
def set(self, **kwargs): def set(self, **kwargs):
""" """
Set a variable or a set of variables on the local db. Set a variable or a set of variables on the local db.
@ -87,8 +87,8 @@ class VariablePlugin(Plugin, EntityManager):
self._db_vars.update(kwargs) self._db_vars.update(kwargs)
return kwargs return kwargs
@action
@ensure_initialized @ensure_initialized
@action
def delete(self, name: str): def delete(self, name: str):
""" """
Delete a variable from the database. Delete a variable from the database.
@ -107,8 +107,8 @@ class VariablePlugin(Plugin, EntityManager):
self._db_vars.pop(name, None) self._db_vars.pop(name, None)
return True return True
@action
@ensure_initialized @ensure_initialized
@action
def unset(self, name: str): def unset(self, name: str):
""" """
Unset a variable by name if it's set on the local db. Unset a variable by name if it's set on the local db.
@ -121,8 +121,8 @@ class VariablePlugin(Plugin, EntityManager):
return self.set(**{name: None}) return self.set(**{name: None})
@action
@ensure_initialized @ensure_initialized
@action
def mget(self, name: str): def mget(self, name: str):
""" """
Get the value of a variable by name from Redis. Get the value of a variable by name from Redis.
@ -133,8 +133,8 @@ class VariablePlugin(Plugin, EntityManager):
return self._redis.mget([name]) return self._redis.mget([name])
@action
@ensure_initialized @ensure_initialized
@action
def mset(self, **kwargs): def mset(self, **kwargs):
""" """
Set a variable or a set of variables on Redis. Set a variable or a set of variables on Redis.
@ -146,8 +146,8 @@ class VariablePlugin(Plugin, EntityManager):
self._redis.mset(**kwargs) self._redis.mset(**kwargs)
return kwargs return kwargs
@action
@ensure_initialized @ensure_initialized
@action
def munset(self, name: str): def munset(self, name: str):
""" """
Unset a Redis variable by name if it's set Unset a Redis variable by name if it's set
@ -157,8 +157,8 @@ class VariablePlugin(Plugin, EntityManager):
return self._redis.delete(name) return self._redis.delete(name)
@action
@ensure_initialized @ensure_initialized
@action
def expire(self, name: str, expire: int): def expire(self, name: str, expire: int):
""" """
Set a variable expiration on Redis Set a variable expiration on Redis
@ -191,8 +191,8 @@ class VariablePlugin(Plugin, EntityManager):
] ]
) )
@action
@ensure_initialized @ensure_initialized
@action
def status(self, *_, **__): def status(self, *_, **__):
variables = { variables = {
name: value for name, value in self._db_vars.items() if value is not None name: value for name, value in self._db_vars.items() if value is not None