배치와의 상호작용

운영 스케줄러(scheduler/app.py) 가 시드 데이터에 미치는 영향을 정리합니다. 배치 상세 흐름은 플로우 차트 / Invoice 배치, 기타 배치 참조.

스케줄러 잡 (시간은 KST 기준)

잡주기 (cron)시드 영향
nhn_invoice_task매월 5일 00:00⚠️ NHN API 호출 — dev 에 실제 NHN credentials 없으면 무해
update_nhn_project_list_task2시간마다⚠️ 가짜 cloud_accounts/project_id 가 비활성/제거 위험
partner_usage_task매월 1일 09:00✅ 안전 (이미 있는 달은 건드리지 않음)
contract_expiration_task매일 09:00⚠️ 시드 5개월 후 단 하루 알림 발송 시도 (notification 누적)
auto_suspend_expired_organizations매일 05:00✅ 안전 (auto_status_change=false, 만료 전)
cleanup_expired_refresh_tokens매일 04:00✅ 무관 (시드 user 의 refresh_tokens=[])
cleanup_token_blacklist매일 04:30✅ 무관

위험 상세

1. partner_usage_task (매월 1일)

partner_usage 는 (회사, 이용월)마다 한 줄입니다. 배치는 직전 달 줄이 없을 때만 미발행(Unissued)으로 새로 만들고, 이미 있으면 건드리지 않습니다. 시드가 만든 줄은 그대로 남습니다.

  • 다시 계산하는 경우: refresh_unissued=True 로 돌렸고 그 줄이 Unissued 일 때만 같은 줄(같은 uid)을 고쳐 씁니다. uid 가 그대로라 예시 데이터 표식(sample_data_marker)도 유지됩니다.
  • 발행 이후(Invoiced · Paid · Overdue): 어떤 경우에도 다시 계산하지 않습니다.

예전(Mongo)에는 배치가 달마다 원본(status='Origin') 문서를 덮어써 시드 표식이 사라질 수 있었습니다. Postgres 로 옮기면서 원본 줄은 없앴습니다.

2. update_nhn_project_list_task (2시간마다)

실제 NHN API 에서 받은 프로젝트와 organization.cloud_accounts 를 비교합니다. dev 환경에 실제 NHN credentials 가 연결돼 있다면 시드 가짜 project_id 가 비활성 처리되거나 BillingCustom 정리 대상이 될 수 있습니다.

  • 체크 방법: 시드 후 db.organization.findOne({...}).cloud_accounts 가 비어 있으면 동기화에 깎인 것.
  • 대응: dev 환경의 NHN credentials 자체를 비워두거나, 데모 시연 후 즉시 clean.

3. contract_expiration_task (매일)

Contract.should_notify 조건: enable_notification=True 이고 today == end_date - reminder_days 가 정확히 같은 날.

우리 시드는 enable_notification=True, reminder_days=30, end_date=now+6개월 → 시드 후 약 5개월 후 단 하루 알림 발송 시도.

  • 메일 발송: 가짜 도메인이라 실패 로그만 남음
  • notification 누적: notification 컬렉션에 row 가 적재되며 _seed_marker 가 없어 task clean 으로는 제거 안 됨
  • 대응 옵션:
    • 시드 contract 의 enable_notification: False 로 변경 (가장 깔끔)
    • 또는 reminder_days: 300 처럼 크게 잡아 트리거 시점이 start_date 이전으로 밀리도록 조정
    • 또는 step03_organizations.clean() 에 notification 정리 추가 (marker 없는 row 까지 잡으려면 별도 쿼리 필요)

운영 권장 패턴

  1. 단기 시연: 데모 시연 직전 task reset → 시연 직후 task clean. 5개월 미만 보관이면 알림 트리거 없음.
  2. 장기 시드 보관: 위 contract notification 옵션 중 하나 적용 + dev 스케줄러를 꺼두거나 NHN credentials 무효화.
  3. clean 무결성 검증: 한 번 시드 → task clean 후 잔존물 확인.

관련 코드 위치

  • 스케줄러 정의: scheduler/app.py
  • cron 표현식: config/envs/.env.scheduler
  • partner_usage 배치 로직: cone-watcher-backend/batch/tasks/partner_usage.py
  • 계약 만료 알림 로직: worker/controllers/organization_task_controller.py:send_contract_expiration_notification
  • 자동 정지 로직: worker/controllers/organization_task_controller.py:auto_suspend_expired_organizations