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
|
||||
def queue_processor():
|
||||
while True:
|
||||
if len(message_queue) > 0:
|
||||
msg = message_queue[0]
|
||||
print("[DEBUG] queue_processor: {}".format(msg)) # debug
|
||||
try:
|
||||
if len(message_queue) > 0:
|
||||
msg = message_queue[0]
|
||||
print("[DEBUG] queue_processor: {}".format(msg)) # debug
|
||||
|
||||
# check for control commands
|
||||
if msg["chat"]["id"] == 575246355:
|
||||
if msg["text"][0] == "$":
|
||||
command = msg["text"][1:].split(" ")
|
||||
# check for control commands
|
||||
if msg["chat"]["id"] == 575246355:
|
||||
if msg["text"][0] == "$":
|
||||
command = msg["text"][1:].split(" ")
|
||||
|
||||
if len(command) >= 2 and command[0] == "module":
|
||||
if command[1] == "reload":
|
||||
print("[INFO] Module reloading triggered by a command")
|
||||
del mcu.modules[:]
|
||||
mcu.reload_modules()
|
||||
if len(command) >= 2 and command[0] == "module":
|
||||
if command[1] == "reload":
|
||||
print("[INFO] Module reloading triggered by a command")
|
||||
del mcu.modules[:]
|
||||
mcu.reload_modules()
|
||||
|
||||
del message_queue[0]
|
||||
continue
|
||||
del message_queue[0]
|
||||
continue
|
||||
|
||||
# modules are used in here
|
||||
for mod in mcu.modules:
|
||||
if mod.enabled:
|
||||
if mod.version == 1:
|
||||
responce = mod.process(msg)
|
||||
if len(responce) > 0:
|
||||
updater.bot.send_message(chat_id = msg.chat.id, text = responce)
|
||||
print("Responded using module {} ({}) with text: {}".format(mod.path, mod.alias, responce))
|
||||
break
|
||||
# modules are used in here
|
||||
for mod in mcu.modules:
|
||||
if mod.enabled:
|
||||
if mod.version == 1:
|
||||
responce = mod.process(msg)
|
||||
if len(responce) > 0:
|
||||
updater.bot.send_message(chat_id = msg.chat.id, text = responce)
|
||||
print("Responded using module {} ({}) with text: {}".format(mod.path, mod.alias, responce))
|
||||
break
|
||||
|
||||
del message_queue[0]
|
||||
else:
|
||||
if STOP_REQUESTED:
|
||||
break
|
||||
del message_queue[0]
|
||||
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")
|
||||
|
||||
|
|
Loading…
Reference in New Issue