[core] Allow modules to specify default update interval
Expanding on the implementation in d582016
, add a decorator
`core.module.every()` that allows a module to specify how often to
update the module's state.
This can still be overridden using the CLI parameter `interval`.
This commit is contained in:
parent
b66b13211e
commit
bd7ff3c8f1
3 changed files with 18 additions and 0 deletions
|
@ -12,6 +12,15 @@ except Exception as e:
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def every(minutes=0, seconds=0):
|
||||||
|
def decorator_init(init):
|
||||||
|
def call_init(obj, *args, **kwargs):
|
||||||
|
init(obj, *args, **kwargs)
|
||||||
|
if obj.parameter('interval') is None:
|
||||||
|
obj.set('interval', minutes*60 + seconds)
|
||||||
|
return call_init
|
||||||
|
return decorator_init
|
||||||
|
|
||||||
def load(module_name, config=None):
|
def load(module_name, config=None):
|
||||||
error = None
|
error = None
|
||||||
for namespace in [ 'core', 'contrib' ]:
|
for namespace in [ 'core', 'contrib' ]:
|
||||||
|
|
|
@ -35,3 +35,11 @@ class Module(core.module.Module):
|
||||||
|
|
||||||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## `update` vs. `full_text`
|
||||||
|
TODO
|
||||||
|
|
||||||
|
## TODOs
|
||||||
|
- default update interval
|
||||||
|
- scrolling
|
||||||
|
-
|
||||||
|
|
|
@ -8,6 +8,7 @@ import core.module
|
||||||
import core.widget
|
import core.widget
|
||||||
|
|
||||||
class Module(core.module.Module):
|
class Module(core.module.Module):
|
||||||
|
@core.module.every(minutes=60)
|
||||||
def __init__(self, config=None):
|
def __init__(self, config=None):
|
||||||
super().__init__(config, core.widget.Widget(self.full_text))
|
super().__init__(config, core.widget.Widget(self.full_text))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue