apiVersion: apps/v1
kind: Deployment
metadata:
  name: notification-worker
  namespace: vzzpr-backend
  labels:
    app: notification-worker
    version: v1.0.0
spec:
  replicas: 2
  selector:
    matchLabels:
      app: notification-worker
  template:
    metadata:
      labels:
        app: notification-worker
        version: v1.0.0
    spec:
      containers:
        - name: notification-worker
          image: qtechdevexperts/vzzpr-backend-worker:latest
          imagePullPolicy: Always
          command: ["npm", "run", "worker:notification"]
          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=1024"
            - name: NOTIF_WORKER_CONCURRENCY
              value: "2"
            - name: WORKER_HEALTH_PORT
              value: "8092"
            - name: TS_NODE_TRANSPILE_ONLY
              value: "1"
            - name: NODE_ENV
              value: "development"
          ports:
            - containerPort: 8092
              name: health
              protocol: TCP
          resources:
            requests:
              cpu: "100m"
              memory: "256Mi"
            limits:
              cpu: "1"
              memory: "1Gi"
          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('Worker health check passed'); process.exit(0);}).catch(() => {console.log('Worker health check failed'); process.exit(1);});\""
            initialDelaySeconds: 30
            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('Worker readiness check passed'); process.exit(0);}).catch(() => {console.log('Worker readiness check failed'); process.exit(1);});\""
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          securityContext:
            allowPrivilegeEscalation: false
            runAsNonRoot: true
            runAsUser: 1000
            runAsGroup: 1000
            capabilities:
              drop:
                - ALL
---
apiVersion: v1
kind: Service
metadata:
  name: notification-worker
  namespace: vzzpr-backend
  labels:
    app: notification-worker
spec:
  selector:
    app: notification-worker
  ports:
    - port: 8092
      targetPort: 8092
      protocol: TCP
      name: health
  type: ClusterIP 