Browse Source

Ajout script de nettoyage des jobs

develop
William Petit 1 year ago
parent
commit
2b88528210
1 changed files with 20 additions and 0 deletions
  1. 20
    0
      misc/script/cleanup-old-jobs.sh

+ 20
- 0
misc/script/cleanup-old-jobs.sh View File

@@ -0,0 +1,20 @@
1
+#!/usr/bin/env bash
2
+
3
+# Script simpliste de nettoyage des jobs via l'API REST de Marang
4
+
5
+TIMESTAMP_THRESHOLD=$(( $(date -d "-1 week" +"%s") * 1000 ))
6
+MARANG_CREDENTIALS='user:password'
7
+JOBS=$(curl -u "$MARANG_CREDENTIALS" http://127.0.0.1:3000/api/jobs)
8
+
9
+for job_b64 in $(echo $JOBS | jq -r -c "to_entries | .[] | @base64"); do
10
+
11
+  job=$(echo "$job_b64" | base64 -d)
12
+  is_older=$(echo $job | jq ".value.timestamp <= $TIMESTAMP_THRESHOLD")
13
+
14
+  if [ "$is_older" == "true" ]; then
15
+    job_key=$(echo $job | jq -r '.key')
16
+    echo "Deleting job $job_key"...
17
+    curl -u "$MARANG_CREDENTIALS" -XDELETE "http://127.0.0.1:3000/api/jobs/$job_key"
18
+  fi
19
+
20
+done

Loading…
Cancel
Save