From 6f84535f15bfda7cf4d7cf090a864bb9be8a883f Mon Sep 17 00:00:00 2001 From: Remi PLANEL <rplanel@pasteur.fr> Date: Mon, 4 Mar 2024 10:23:50 +0100 Subject: [PATCH] Resolve "Cron Job to clean database and galaxy" --- backend/analysis/api.py | 3 ++- .../commands/clear-sessions-history.py | 24 +++++++++++++++++-- .../djangoninja/templates/deployment.yaml | 10 ++++---- deploy/templates/pvc-uploaded-files.yaml | 12 ---------- 4 files changed, 29 insertions(+), 20 deletions(-) delete mode 100644 deploy/templates/pvc-uploaded-files.yaml diff --git a/backend/analysis/api.py b/backend/analysis/api.py index ce4129e..e9cdc15 100644 --- a/backend/analysis/api.py +++ b/backend/analysis/api.py @@ -29,7 +29,8 @@ from analysis.model_schemas import ( SystemOutSchema, ) -session_expiry = 2628000 +# session_expiry = 2628000 +session_expiry = 10 router = Router() diff --git a/backend/analysis/management/commands/clear-sessions-history.py b/backend/analysis/management/commands/clear-sessions-history.py index 8a53fc6..928615d 100644 --- a/backend/analysis/management/commands/clear-sessions-history.py +++ b/backend/analysis/management/commands/clear-sessions-history.py @@ -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) diff --git a/deploy/charts/djangoninja/templates/deployment.yaml b/deploy/charts/djangoninja/templates/deployment.yaml index e92f4dd..7eb4b59 100644 --- a/deploy/charts/djangoninja/templates/deployment.yaml +++ b/deploy/charts/djangoninja/templates/deployment.yaml @@ -89,8 +89,8 @@ spec: resources: {{- toYaml .Values.resources | nindent 12 }} volumeMounts: - - mountPath: /code/public/static - name: server-static + # - mountPath: /code/public/static + # name: server-static - mountPath: /uploaded-files name: uploaded-files {{- with .Values.nodeSelector }} @@ -106,9 +106,9 @@ spec: {{- toYaml . | nindent 8 }} {{- end }} volumes: - - name: server-static - persistentVolumeClaim: - claimName: server-static + # - name: server-static + # persistentVolumeClaim: + # claimName: server-static - name: uploaded-files emptyDir: sizeLimit: 5Gi diff --git a/deploy/templates/pvc-uploaded-files.yaml b/deploy/templates/pvc-uploaded-files.yaml deleted file mode 100644 index 8319f66..0000000 --- a/deploy/templates/pvc-uploaded-files.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: "uploaded-files" -spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 10Gi - storageClassName: {{ .Values.uploadedFile.storageClassName }} -status: {} -- GitLab