main.py: secured queue_processor with try/except due to receiving multiple None messages, will try to figure out what is broken there
This commit is contained in:
parent
a1d76d3bad
commit
eb51a5d2ee
65
main.py
65
main.py
|
@ -155,40 +155,49 @@ class ModuleControlUnit:
|
||||||
# synchronous message processor
|
# synchronous message processor
|
||||||
def queue_processor():
|
def queue_processor():
|
||||||
while True:
|
while True:
|
||||||
if len(message_queue) > 0:
|
try:
|
||||||
msg = message_queue[0]
|
if len(message_queue) > 0:
|
||||||
print("[DEBUG] queue_processor: {}".format(msg)) # debug
|
msg = message_queue[0]
|
||||||
|
print("[DEBUG] queue_processor: {}".format(msg)) # debug
|
||||||
|
|
||||||
# check for control commands
|
# check for control commands
|
||||||
if msg["chat"]["id"] == 575246355:
|
if msg["chat"]["id"] == 575246355:
|
||||||
if msg["text"][0] == "$":
|
if msg["text"][0] == "$":
|
||||||
command = msg["text"][1:].split(" ")
|
command = msg["text"][1:].split(" ")
|
||||||
|
|
||||||
if len(command) >= 2 and command[0] == "module":
|
if len(command) >= 2 and command[0] == "module":
|
||||||
if command[1] == "reload":
|
if command[1] == "reload":
|
||||||
print("[INFO] Module reloading triggered by a command")
|
print("[INFO] Module reloading triggered by a command")
|
||||||
del mcu.modules[:]
|
del mcu.modules[:]
|
||||||
mcu.reload_modules()
|
mcu.reload_modules()
|
||||||
|
|
||||||
del message_queue[0]
|
del message_queue[0]
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# modules are used in here
|
# modules are used in here
|
||||||
for mod in mcu.modules:
|
for mod in mcu.modules:
|
||||||
if mod.enabled:
|
if mod.enabled:
|
||||||
if mod.version == 1:
|
if mod.version == 1:
|
||||||
responce = mod.process(msg)
|
responce = mod.process(msg)
|
||||||
if len(responce) > 0:
|
if len(responce) > 0:
|
||||||
updater.bot.send_message(chat_id = msg.chat.id, text = responce)
|
updater.bot.send_message(chat_id = msg.chat.id, text = responce)
|
||||||
print("Responded using module {} ({}) with text: {}".format(mod.path, mod.alias, responce))
|
print("Responded using module {} ({}) with text: {}".format(mod.path, mod.alias, responce))
|
||||||
break
|
break
|
||||||
|
|
||||||
del message_queue[0]
|
del message_queue[0]
|
||||||
else:
|
|
||||||
if STOP_REQUESTED:
|
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
time.sleep(1)
|
if STOP_REQUESTED:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
time.sleep(1)
|
||||||
|
except Exception as e:
|
||||||
|
print("[ERROR] queue_processor: current message queue: {}".format(message_queue))
|
||||||
|
print("[ERROR] queue_processor: error while processing message, trying to delete it...")
|
||||||
|
try:
|
||||||
|
del message_queue[0]
|
||||||
|
print("[INFO] queue_processor: deleted broken message from the queue")
|
||||||
|
except:
|
||||||
|
print("[WARN] queue_processor: message seems absent, whatever")
|
||||||
|
|
||||||
print("[INFO] queue_processor thread stops successfully")
|
print("[INFO] queue_processor thread stops successfully")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue