apiVersion: batch/v1
kind: CronJob
metadata:
  name: sync-backend-data-pool
  namespace: frontend
spec:
  schedule: "*/5 * * * *"  # Runs every 5 minutes - adjust as needed
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 3
  concurrencyPolicy: Forbid  # Prevents overlapping executions
  jobTemplate:
    spec:
      template:
        metadata:
          labels:
            app: sync-backend-data-pool
        spec:
          restartPolicy: OnFailure
          containers:
            - name: sync-backend-data-pool
              image: git.trai-infra.comstack.de/marian.lippitz/tap-frontend:latest
              command: ["php", "artisan", "schedule:run"]
              envFrom:
                - configMapRef:
                    name: tap-frontend-config
              volumeMounts:
                - name: tap-frontend-config-volume
                  mountPath: /var/www/html/.env
                  subPath: env
          volumes:
            - name: tap-frontend-config-volume
              configMap:
                name: tap-frontend-config
---
apiVersion: batch/v1
kind: Job
metadata:
  name: sync-backend-data-pool-manual
  namespace: frontend
spec:
  template:
    metadata:
      labels:
        app: sync-backend-data-pool-manual
    spec:
      restartPolicy: OnFailure
      containers:
        - name: sync-backend-data-pool
          image: git.trai-infra.comstack.de/marian.lippitz/tap-frontend:latest
          command: ["php", "artisan", "tinker", "--execute=dispatch(new App\\Jobs\\SyncBackendDataPool(fullSync: false, batchSize: 1000))"]
          envFrom:
            - configMapRef:
                name: tap-frontend-config
          volumeMounts:
            - name: tap-frontend-config-volume
              mountPath: /var/www/html/.env
              subPath: env
      volumes:
        - name: tap-frontend-config-volume
          configMap:
            name: tap-frontend-config
