run gc in db ctx
This commit is contained in:
parent
1855cc3252
commit
d41416b4d7
|
|
@ -611,6 +611,9 @@ def main():
|
||||||
config=config,
|
config=config,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Run cleanup tasks before exiting database context
|
||||||
|
run_cleanup()
|
||||||
|
|
||||||
except (KeyboardInterrupt, AgentInterrupt):
|
except (KeyboardInterrupt, AgentInterrupt):
|
||||||
print()
|
print()
|
||||||
print(" 👋 Bye!")
|
print(" 👋 Bye!")
|
||||||
|
|
@ -624,21 +627,11 @@ def run_cleanup():
|
||||||
# Import the key facts cleaner agent
|
# Import the key facts cleaner agent
|
||||||
from ra_aid.agents.key_facts_gc_agent import run_key_facts_gc_agent
|
from ra_aid.agents.key_facts_gc_agent import run_key_facts_gc_agent
|
||||||
|
|
||||||
# Get the count of key facts
|
# Run the key facts garbage collection agent regardless of the number of facts
|
||||||
from ra_aid.database.repositories.key_fact_repository import KeyFactRepository
|
run_key_facts_gc_agent()
|
||||||
key_fact_repository = KeyFactRepository()
|
|
||||||
|
|
||||||
# Only run the cleaner if we have more than 30 facts
|
|
||||||
facts = key_fact_repository.get_all()
|
|
||||||
if len(facts) > 30:
|
|
||||||
run_key_facts_gc_agent()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to run cleanup tasks: {str(e)}")
|
logger.error(f"Failed to run cleanup tasks: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
try:
|
main()
|
||||||
main()
|
|
||||||
finally:
|
|
||||||
# Run cleanup tasks at program exit
|
|
||||||
run_cleanup()
|
|
||||||
Loading…
Reference in New Issue