# cache-worker — pre-compute discover, finance, travel
# docs/architecture: 02-k3s-microservices-spec.md §3.15, 05-gaps-and-best-practices §6
# activeDeadlineSeconds защищает от зависших задач

---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: cache-worker-finance
  namespace: gooseek
spec:
  schedule: "*/2 * * * *"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      activeDeadlineSeconds: 300
      template:
        spec:
          restartPolicy: OnFailure
          containers:
            - name: cache-worker
              image: gooseek/cache-worker:latest
              args: ["--task=finance"]
              env:
                - name: REDIS_URL
                  valueFrom:
                    secretKeyRef:
                      name: redis-credentials
                      key: url
                - name: FINANCE_SVC_URL
                  value: "http://finance-svc.gooseek:3003"
---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: cache-worker-discover
  namespace: gooseek
spec:
  schedule: "*/15 * * * *"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      activeDeadlineSeconds: 600
      template:
        spec:
          restartPolicy: OnFailure
          containers:
            - name: cache-worker
              image: gooseek/cache-worker:latest
              args: ["--task=discover"]
              env:
                - name: REDIS_URL
                  valueFrom:
                    secretKeyRef:
                      name: redis-credentials
                      key: url
                - name: DISCOVER_SVC_URL
                  value: "http://discover-svc.gooseek:3002"
---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: cache-worker-travel
  namespace: gooseek
spec:
  schedule: "0 */4 * * *"
  concurrencyPolicy: Forbid
  jobTemplate:
    spec:
      activeDeadlineSeconds: 1200
      template:
        spec:
          restartPolicy: OnFailure
          containers:
            - name: cache-worker
              image: gooseek/cache-worker:latest
              args: ["--task=travel"]
              env:
                - name: REDIS_URL
                  valueFrom:
                    secretKeyRef:
                      name: redis-credentials
                      key: url
                - name: TRAVEL_SVC_URL
                  value: "http://travel-svc.gooseek:3004"
