keys = set(existing_handler.keys())
keys.remove("created_time") // the new handler has none
values = [existing_handler[key] for key in keys]
if keys == new_keys and set(new_values)== set(values):
// if keep is True we will add a new one// if keep is False we will drop this anywaycontinue
After Change
for existing_handler in existing_handlers:
// we match two handlers according to their tagsif existing_handler["tags"] == msg.handler["tags"]:
matched = existing_handler// if an existing_handler match the passed in handler,// we ignore it in for loopcontinueelse:
// if an existing_handler does not match the passed in// handler, we keep it
replacement_handlers.append(existing_handler)
if msg.keep:
msg.handler["created_time"] = time.time()
replacement_handlers.append(msg.handler)
if matched is not None:
debug(
f"> Replacing a Request Handler {matched} with: {msg.handler}"
)
else:
debug(f"> Adding a Request Handler {msg.handler}")
else:
debug(f"> Removing a Request Handler with: {msg.handler}")
setattr(node, "request_handlers", replacement_handlers)