Skip to content

Commit ba81880

Browse files
fix: add cron job for optimus DB cleanup (#16)
* fix: add cron job for optimus DB cleanup * fix: configurable optimus db cleanup template
1 parent 09e3209 commit ba81880

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

stable/optimus/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ type: application
99
# This is the chart version. This version number should be incremented each time you make changes
1010
# to the chart and its templates, including the app version.
1111
# Versions are expected to follow Semantic Versioning (https://semver.org/)
12-
version: 0.0.3
12+
version: 0.0.4
1313

1414
# This is the version number of the application being deployed. This version number should be
1515
# incremented each time you make changes to the application. Versions are not expected to
1616
# follow Semantic Versioning. They should reflect the version the application is using.
1717
# It is recommended to use it with quotes.
18-
appVersion: "0.3.0"
18+
appVersion: "0.6.0"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{{- if .Values.cleanupConfig.enabled -}}
2+
apiVersion: batch/v1beta1
3+
kind: CronJob
4+
metadata:
5+
name: {{ include "app.fullname" . }}-cleanup
6+
spec:
7+
schedule: {{ .Values.cleanupConfig.schedule }}
8+
concurrencyPolicy: {{ .Values.cleanupConfig.concurrencyPolicy }}
9+
jobTemplate:
10+
spec:
11+
template:
12+
spec:
13+
containers:
14+
- name: {{ include "app.fullname" . }}-cleanup
15+
image: {{ .Values.cleanupConfig.image }}
16+
envFrom:
17+
- configMapRef:
18+
name: {{ template "app.fullname" . }}
19+
env:
20+
- name: QUERIES
21+
value: "{{- range .Values.cleanupConfig.queries -}} {{.}} {{- end }}"
22+
command: ["sh", "-c", "set -x; echo $QUERIES; psql $OPTIMUS_SERVE_DB_DSN -c \"$QUERIES\";"]
23+
restartPolicy: {{ .Values.cleanupConfig.restartPolicy }}
24+
{{- end }}

stable/optimus/values.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ config:
6868

6969
secretConfig: {}
7070

71+
cleanupConfig:
72+
enabled: true
73+
schedule: "0 0 1 * *" # Runs At 00:00 on day-of-month 1
74+
image: "postgres:15.2-alpine3.17"
75+
restartPolicy: OnFailure
76+
concurrencyPolicy: Forbid
77+
queries:
78+
- "delete from sensor_run where start_time < now() - Interval '30d';"
79+
- "delete from task_run where start_time < now() - Interval '30d';"
80+
- "delete from hook_run where start_time < now() - Interval '30d';"
81+
- "delete from job_run where start_time < now() - Interval '60d';"
82+
7183
service:
7284
type: ClusterIP
7385
ports:

0 commit comments

Comments
 (0)