apiVersion: batch/v1
kind: Job
metadata:
  name: demo-seed-forecasts
  namespace: bakery-ia
  labels:
    app: demo-seed
    component: initialization
  annotations:
    "helm.sh/hook": post-install,post-upgrade
    "helm.sh/hook-weight": "40"  # Last seed job
spec:
  ttlSecondsAfterFinished: 3600
  template:
    metadata:
      labels:
        app: demo-seed-forecasts
    spec:
      initContainers:
      - name: wait-for-forecasting-migration
        image: busybox:1.36
        command:
        - sh
        - -c
        - |
          echo "Waiting 30 seconds for forecasting-migration to complete..."
          sleep 30
      - name: wait-for-forecasting-service
        image: curlimages/curl:latest
        command:
        - sh
        - -c
        - |
          echo "Waiting for forecasting-service to be ready..."
          until curl -f http://forecasting-service.bakery-ia.svc.cluster.local:8000/health/ready > /dev/null 2>&1; do
            echo "forecasting-service not ready yet, waiting..."
            sleep 5
          done
          echo "forecasting-service is ready!"
      containers:
      - name: seed-forecasts
        image: bakery/forecasting-service:latest
        command: ["python", "/app/scripts/demo/seed_demo_forecasts.py"]
        env:
        - name: FORECASTING_DATABASE_URL
          valueFrom:
            secretKeyRef:
              name: database-secrets
              key: FORECASTING_DATABASE_URL
        - name: DEMO_MODE
          value: "production"
        - name: LOG_LEVEL
          value: "INFO"
        resources:
          requests:
            memory: "512Mi"
            cpu: "200m"
          limits:
            memory: "1Gi"
            cpu: "1000m"
      restartPolicy: OnFailure
      serviceAccountName: demo-seed-sa
