Skip to content

Commit

Permalink
added general exception watcher and restart on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
exddc committed Jun 17, 2024
1 parent a60f24a commit b91d145
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,24 @@ def watch_env_file(agent_instance):


if __name__ == "__main__":
agent = Agent()
agent.run()

watcher_thread = threading.Thread(target=watch_env_file, args=(agent,))
watcher_thread.daemon = True
watcher_thread.start()

try:
while True:
time.sleep(1)
except KeyboardInterrupt:
agent.stop()
# pylint: disable=broad-except
except Exception as e:
LOGGER.error("Agent failed: %s", str(e))
agent.stop()
while True:
try:
agent = Agent()
agent.run()

watcher_thread = threading.Thread(target=watch_env_file, args=(agent,))
watcher_thread.daemon = True
watcher_thread.start()

while True:
time.sleep(1)
except KeyboardInterrupt:
LOGGER.info("KeyboardInterrupt received. Stopping agent.")
agent.stop()
break
# pylint: disable=broad-except
except Exception as e:
LOGGER.error("Agent failed: %s", str(e))
agent.stop()
LOGGER.info("Restarting agent...")
time.sleep(0.5)

0 comments on commit b91d145

Please sign in to comment.