# Worker de file d'attente + CronJob du scheduler Laravel (AKS).
# Le worker traite les jobs (envoi d'e-mails, génération de PDF en lot, etc.).
apiVersion: apps/v1
kind: Deployment
metadata:
  name: plateforme-formation-worker
  labels: { app: plateforme-formation-worker }
spec:
  replicas: 1
  selector:
    matchLabels: { app: plateforme-formation-worker }
  template:
    metadata:
      labels: { app: plateforme-formation-worker }
    spec:
      containers:
        - name: worker
          image: acrformation.azurecr.io/plateforme-formation:1.0
          command: ["php", "artisan", "queue:work", "--tries=3", "--max-time=3600"]
          envFrom:
            - configMapRef: { name: app-config }
            - secretRef: { name: app-secrets }
          env:
            - name: RUN_MIGRATIONS
              value: "false"   # seul le pod web migre
          resources:
            requests: { cpu: "100m", memory: "192Mi" }
            limits:   { cpu: "500m", memory: "384Mi" }
---
# Scheduler : exécute `php artisan schedule:run` chaque minute.
apiVersion: batch/v1
kind: CronJob
metadata:
  name: plateforme-formation-scheduler
spec:
  schedule: "* * * * *"
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 1
  failedJobsHistoryLimit: 3
  jobTemplate:
    spec:
      template:
        spec:
          restartPolicy: Never
          containers:
            - name: scheduler
              image: acrformation.azurecr.io/plateforme-formation:1.0
              command: ["php", "artisan", "schedule:run"]
              envFrom:
                - configMapRef: { name: app-config }
                - secretRef: { name: app-secrets }
              env:
                - name: RUN_MIGRATIONS
                  value: "false"
