apiVersion: apps/v1
kind: Deployment
metadata:
  name: video-worker
  namespace: vzzpr-backend
  labels:
    app: video-worker
    version: v1.0.0
spec:
  replicas: 2
  selector:
    matchLabels:
      app: video-worker
  template:
    metadata:
      labels:
        app: video-worker
        version: v1.0.0
    spec:
      containers:
        - name: video-worker
          image: qtechdevexperts/vzzpr-backend-worker:latest
          imagePullPolicy: Always
          command: ["npm", "run", "worker:video"]
          envFrom:
            - configMapRef:
                name: vzzpr-config
            - secretRef:
                name: vzzpr-secrets
          env:
            - name: REDIS_HOST
              value: "redis"
            - name: REDIS_PORT
              value: "6370"
            - name: NODE_OPTIONS
              value: "--max-old-space-size=4096"
            - name: VIDEO_WORKER_CONCURRENCY
              value: "2"
            - name: WORKER_HEALTH_PORT
              value: "8091"
            - name: TS_NODE_TRANSPILE_ONLY
              value: "1"
            - name: NODE_ENV
              value: "development"
          ports:
            - containerPort: 8091
              name: health
              protocol: TCP
          resources:
            requests:
              cpu: "500m"
              memory: "1Gi"
            limits:
              cpu: "4"
              memory: "8Gi"
          volumeMounts:
            - name: video-processing-temp
              mountPath: /tmp/video-processing
          livenessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - "node -e \"const Redis = require('ioredis'); const redis = new Redis({host: process.env.REDIS_HOST || 'redis', port: process.env.REDIS_PORT || 6370}); redis.ping().then(() => {console.log('Video worker health check passed'); process.exit(0);}).catch(() => {console.log('Video worker health check failed'); process.exit(1);});\""
            initialDelaySeconds: 60
            periodSeconds: 30
            timeoutSeconds: 10
            failureThreshold: 3
          readinessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - "node -e \"const Redis = require('ioredis'); const redis = new Redis({host: process.env.REDIS_HOST || 'redis', port: process.env.REDIS_PORT || 6370}); redis.ping().then(() => {console.log('Video worker readiness check passed'); process.exit(0);}).catch(() => {console.log('Video worker readiness check failed'); process.exit(1);});\""
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          securityContext:
            allowPrivilegeEscalation: false
            runAsNonRoot: true
            runAsUser: 1000
            runAsGroup: 1000
            capabilities:
              drop:
                - ALL
      volumes:
        - name: video-processing-temp
          emptyDir:
            sizeLimit: 10Gi
---
apiVersion: v1
kind: Service
metadata:
  name: video-worker
  namespace: vzzpr-backend
  labels:
    app: video-worker
spec:
  selector:
    app: video-worker
  ports:
    - port: 8091
      targetPort: 8091
      protocol: TCP
      name: health
  type: ClusterIP 