{{- if .Values.extractWorker.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "firecrawl.fullname" . }}-extract-worker
  labels:
    app: {{ include "firecrawl.name" . }}-extract-worker
spec:
  replicas: {{ .Values.extractWorker.replicaCount | default 1 }}
  selector:
    matchLabels:
      app: {{ include "firecrawl.name" . }}-extract-worker
  template:
    metadata:
      labels:
        app: {{ include "firecrawl.name" . }}-extract-worker
    spec:
      {{- if .Values.image.dockerSecretEnabled }}
      imagePullSecrets:
        {{- toYaml .Values.imagePullSecrets | nindent 8 }}
      {{- end }}
      terminationGracePeriodSeconds: 60
      containers:
        - name: extract-worker
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command: [ "node" ]
          args: [ "--max-old-space-size=3072", "dist/src/services/extract-worker.js" ]
          ports:
            - containerPort: {{ .Values.extractWorker.port | int }}
          env:
            - name: FLY_PROCESS_GROUP
              value: "extract-worker"
            - name: EXTRACT_WORKER_PORT
              value: {{ .Values.extractWorker.port | quote }}
            - name: NUQ_POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
          envFrom:
            - configMapRef:
                name: {{ include "firecrawl.fullname" . }}-config
            - secretRef:
                name: {{ include "firecrawl.fullname" . }}-secret
          {{- if and .Values.resources.enabled .Values.extractWorker.resources }}
          resources:
            {{- toYaml .Values.extractWorker.resources | nindent 12 }}
          {{- end }}
          livenessProbe:
            httpGet:
              path: /liveness
              port: {{ .Values.extractWorker.port | int }}
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /health
              port: {{ .Values.extractWorker.port | int }}
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 5
            successThreshold: 1
            failureThreshold: 3
{{- end }}
