[module/spaceapi] fix freeze on unreachable API
The statusbar was freezing for several minutes if it could not reach the API endpoint. This is because of a missing timeout statement in the call to python.requests's get function. - Added spaceapi.timeout parameter - Added timeout to requests Signed-off-by: Tobias Manske <tobias.manske@mailbox.org>
This commit is contained in:
parent
0a03fc859e
commit
8eaded9405
1 changed files with 7 additions and 1 deletions
|
@ -10,6 +10,8 @@ Parameters:
|
||||||
* spaceapi.name: String overwriting the space name
|
* spaceapi.name: String overwriting the space name
|
||||||
* spaceapi.prefix: Prefix for the space string
|
* spaceapi.prefix: Prefix for the space string
|
||||||
* spaceapi.interval: time between updates in minutes
|
* spaceapi.interval: time between updates in minutes
|
||||||
|
* spaceapi.timeout: Maximum time in seconds to wait for a response from API
|
||||||
|
endpoint
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import bumblebee.input
|
import bumblebee.input
|
||||||
|
@ -36,6 +38,10 @@ class Module(bumblebee.engine.Module):
|
||||||
# so you're able to distinguish
|
# so you're able to distinguish
|
||||||
self._name = self.parameter("name", default="")
|
self._name = self.parameter("name", default="")
|
||||||
|
|
||||||
|
# The timeout prevents the statusbar from blocking when the destination
|
||||||
|
# can't be reached.
|
||||||
|
self._timeout = self.parameter("timeout", default=2)
|
||||||
|
|
||||||
# Only execute every 5 minutes by default
|
# Only execute every 5 minutes by default
|
||||||
self.interval(self.parameter("interval", default=5))
|
self.interval(self.parameter("interval", default=5))
|
||||||
|
|
||||||
|
@ -61,7 +67,7 @@ class Module(bumblebee.engine.Module):
|
||||||
|
|
||||||
def update(self, widgets):
|
def update(self, widgets):
|
||||||
try:
|
try:
|
||||||
with requests.get(self._url) as u:
|
with requests.get(self._url, timeout=self.timeout) as u:
|
||||||
json = u.json()
|
json = u.json()
|
||||||
self._open = json["state"]["open"]
|
self._open = json["state"]["open"]
|
||||||
self._name = self.parameter("name", default=json["space"])
|
self._name = self.parameter("name", default=json["space"])
|
||||||
|
|
Loading…
Reference in a new issue