Run single tasks

This commit is contained in:
2024-10-30 20:24:12 +01:00
parent f2b9df7611
commit 786a230e78
9 changed files with 500 additions and 248 deletions

View File

@ -22,8 +22,9 @@ class MessageProcessor():
MANAGEMENT_URL = os.environ.get('MANAGEMENT_URL', 'http://127.0.0.1:80').strip().strip('/')
AGENTS_LIST = os.environ.get('AGENTS_LIST', 'ums.example.example:AGENT_CLASSES').strip()
def __init__(self):
def __init__(self, disable_messages:bool=False):
self.counts = 0
self.disable_messages = disable_messages
module_name, var_name = self.AGENTS_LIST.split(':')
agents_module = importlib.import_module(module_name)
@ -82,14 +83,18 @@ class MessageProcessor():
)
def _send_message(self, message:AgentMessage) -> bool:
r = requests.post(
"{}/message".format(self.MANAGEMENT_URL),
data=message.model_dump_json(),
headers={"accept" : "application/json", "content-type" : "application/json"}
)
if not self.disable_messages:
r = requests.post(
"{}/message".format(self.MANAGEMENT_URL),
data=message.model_dump_json(),
headers={"accept" : "application/json", "content-type" : "application/json"}
)
if r.status_code == 200:
return True
if r.status_code == 200:
return True
else:
logger.warning(f"Error sending message to management! {(r.text, r.headers)}")
return False
else:
logger.warning(f"Error sending message to management! {(r.text, r.headers)}")
return False
print("\tMessages disabled: Requested to send message to management:")
print(message.model_dump_json(indent=2))