Skip to content
Snippets Groups Projects

Resolve "Cron Job to clean database and galaxy"

Merged Remi PLANEL requested to merge script-clean-database-and-gx-histories into main
Files
4
@@ -30,11 +30,31 @@ class Command(BaseCommand):
email=options["galaxyemail"],
galaxy_instance=gi,
).first()
print(gu)
histories = AnalysisHistory.objects.filter(
analysis_owner=gu, session__expire_date__lt=datetime.now().astimezone()
)
for h in histories:
print(f"Delete expire history {h.name} expired : {h.session.expire_date}")
h.delete()
try:
h.analysis_owner.obj_gi.histories.delete(id_=h.galaxy_id, purge=True)
except ConnectionError as e:
print(e)
raise e
else:
h.delete()
# clean orphan galaxy histories
histories = gu.obj_gi.gi.histories.get_histories()
histories_from_host = [
h for h in histories if settings.DF_HOSTNAME in h["tags"]
]
for h in histories_from_host:
galaxy_id = h["id"]
# check if in database.
# if not, purge it
history = AnalysisHistory.objects.filter(galaxy_id=galaxy_id)
if not history.exists():
print(f"Delete orphan history {h['name']}.")
gu.obj_gi.gi.histories.delete_history(galaxy_id, purge=True)
Loading