# =============================================================================
# Weekly Report CronJob - Phase 21.3 定期報告
# =============================================================================
# 每週五 18:00 台北 (10:00 UTC) 發送週報到 Telegram
#
# 2026-03-31 Claude Code (ADR-041)
# =============================================================================

apiVersion: batch/v1
kind: CronJob
metadata:
  name: weekly-report
  namespace: awoooi-prod
  labels:
    app: awoooi
    component: weekly-report
    phase: "21.3"
spec:
  # 每週五 10:00 UTC = 18:00 台北
  schedule: "0 10 * * 5"
  # 時區設定 (K8s 1.27+)
  timeZone: "Asia/Taipei"
  # 並發策略: 禁止並發執行
  concurrencyPolicy: Forbid
  # 保留歷史
  successfulJobsHistoryLimit: 4
  failedJobsHistoryLimit: 2
  # 錯過執行的處理 (最多延遲 10 分鐘)
  startingDeadlineSeconds: 600
  jobTemplate:
    spec:
      # 失敗重試
      backoffLimit: 2
      # 執行超時 (10 分鐘)
      activeDeadlineSeconds: 600
      template:
        metadata:
          labels:
            app: awoooi
            component: weekly-report
        spec:
          restartPolicy: OnFailure
          containers:
            - name: weekly-report
              image: 192.168.0.110:5000/awoooi-api:latest
              imagePullPolicy: Always
              command:
                - python
                - -m
                - src.services.weekly_report_service
              env:
                - name: TZ
                  value: "Asia/Taipei"
              envFrom:
                - configMapRef:
                    name: awoooi-config
                - secretRef:
                    name: awoooi-secrets
              resources:
                requests:
                  cpu: "100m"
                  memory: "128Mi"
                limits:
                  cpu: "500m"
                  memory: "256Mi"
          # 使用 API 的 ServiceAccount (需要 RBAC)
          serviceAccountName: awoooi-api
