Skip to content

Commit

Permalink
fix(subsys/broker/worker): write errors using the error logging level
Browse files Browse the repository at this point in the history
  • Loading branch information
guendto committed Oct 3, 2021
1 parent fde434b commit 8a40b3b
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/jomiel/subsys/broker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def new_socket(self):
try:
sck.connect(self.dealer_endpoint)
except ZMQError as error:
self.log(f"{error} ({self.dealer_endpoint})")
self.log_error(f"{error} ({self.dealer_endpoint})")
exit_error()
self.log("connected to <%s>" % self.dealer_endpoint)
return sck
Expand All @@ -77,32 +77,39 @@ def io_loop(self):
self.log("awaiting")
self.message_receive()
except DecodeError as error:
self.log(
self.log_error(
"received invalid message: %s" % (error),
"error",
)
self.message_send(ResponseBuilder(error).response)
self.renew_socket()
finally:
self.log("reset")

def log(self, text, msgtype="debug"):
"""Write a new (debug) worker entry to the logger."""
def _log(self, text, msgtype):
"""Write new log event to the logger."""
logger = getattr(lg(), msgtype)
logger(
"subsystem/broker<worker#%03d>: %s",
self.worker_id,
text,
)

def log(self, text):
"""Write an "debug" event to the logger."""
self._log(text, "debug")

def log_error(self, text):
"""Write an "error" event to the logger."""
self._log(text, "error")

def run(self):
"""Runs the worker."""
try:
self.io_loop()
except ContextTerminated as msg:
self.log(msg)
except KeyboardInterrupt:
self.log("interrupted")
self.log_error("interrupted")
finally:
self.socket.close()
self.log("exit")
Expand Down

0 comments on commit 8a40b3b

Please sign in to comment.