Skip to content

Commit

Permalink
feat: add clenaup job to delete old entries in pokemon table (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathnogueira authored Sep 9, 2024
1 parent afa76fe commit 25419a7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
28 changes: 28 additions & 0 deletions charts/pokeshop-demo/templates/cronjob.cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.pokeshop.cleanup.enabled -}}
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "pokeshop-demo.fullname" . }}-cleanup
labels:
{{- include "pokeshop-demo.api.labels" . | nindent 4 }}
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: pg-cleanup
image: jbergknoff/postgresql-client
imagePullPolicy: IfNotPresent
command:
- psql
args:
- "-d"
- "$(DATABASE_URL)"
- -c
- delete from pokemon where "createdAt" < current_timestamp - interval '1 day'
env:
{{- toYaml .Values.pokeshop.env | nindent 16 }}
restartPolicy: OnFailure
{{- end -}}
5 changes: 4 additions & 1 deletion charts/pokeshop-demo/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pokeshop:
enabled: false
hostname: pokeshop.localdev

cleanup:
enabled: false

api:
resources: {}
replicaCount: 1
Expand All @@ -33,7 +36,7 @@ pokeshop:
- name: COLLECTOR_ENDPOINT
value: http://ttdemo-opentelemetry-collector:44317
- name: DATABASE_URL
value: postgresql://ashketchum:squirtle123@postgresql:5432/pokeshop?schema=public
value: postgresql://ashketchum:squirtle123@postgresql:5432/pokeshop
- name: REDIS_URL
value: redis-headless
- name: RABBITMQ_HOST
Expand Down

0 comments on commit 25419a7

Please sign in to comment.