apiVersion: batch/v1
kind: Job
metadata:
  name: "{{ id }}"
  labels:
    role: "background-job"
    job_type: {{ job_type }}
    btrix.org: {{ oid }}

spec:
  ttlSecondsAfterFinished: 90
  backoffLimit: 3
  template:
    spec:
      restartPolicy: Never
      priorityClassName: bg-job
      podFailurePolicy:
        rules:
        - action: FailJob
          onExitCodes:
            containerName: btrixbgjob
            operator: NotIn
            values: [0]
      
      volumes:
        - name: ops-configs
          secret:
            secretName: ops-configs

      containers:
        - name: btrixbgjob
          image: {{ backend_image }}
          imagePullPolicy: {{ pull_policy }}
          env:
          - name: BG_JOB_TYPE
            value: {{ job_type }}

          - name: OID
            value: {{ oid }}

          - name: CRAWL_TYPE
            value: {{ crawl_type }}

          envFrom:
            - configMapRef:
                name: backend-env-config
            - secretRef:
                name: mongo-auth

          volumeMounts:
            - name: ops-configs
              mountPath: /ops-configs/

          command: ["python3", "-m", "btrixcloud.main_bg"]

          resources:
            limits:
              memory: "200Mi"

            requests:
              memory: "200Mi"
              cpu: "50m"
