apiVersion: batch/v1 kind: CronJob metadata: name: usage-tracker namespace: bakery-ia labels: app: usage-tracker component: cron spec: # Schedule: Daily at 2 AM UTC schedule: "0 2 * * *" # Keep last 3 successful jobs and 1 failed job for debugging successfulJobsHistoryLimit: 3 failedJobsHistoryLimit: 1 # Don't start new job if previous one is still running concurrencyPolicy: Forbid # Job must complete within 30 minutes startingDeadlineSeconds: 1800 jobTemplate: spec: # Retry up to 2 times if job fails backoffLimit: 2 # Job must complete within 20 minutes activeDeadlineSeconds: 1200 template: metadata: labels: app: usage-tracker component: cron spec: restartPolicy: OnFailure # Use tenant service image (it has access to all models) containers: - name: usage-tracker image: your-registry/bakery-ia-tenant-service:latest imagePullPolicy: Always command: - python3 - /app/scripts/track_daily_usage.py env: # Database connection - name: DATABASE_URL valueFrom: secretKeyRef: name: database-credentials key: url # Redis connection - name: REDIS_URL valueFrom: configMapKeyRef: name: app-config key: redis-url # Service settings - name: LOG_LEVEL value: "INFO" - name: PYTHONUNBUFFERED value: "1" resources: requests: memory: "256Mi" cpu: "100m" limits: memory: "512Mi" cpu: "500m" # Health check: ensure script completes successfully livenessProbe: exec: command: - /bin/sh - -c - pgrep -f track_daily_usage.py initialDelaySeconds: 10 periodSeconds: 60 failureThreshold: 3 --- apiVersion: v1 kind: ConfigMap metadata: name: usage-tracker-config namespace: bakery-ia data: # You can add additional configuration here if needed schedule: "Daily at 2 AM UTC" description: "Tracks daily usage snapshots for predictive analytics"