[STK1-05] 폴링 스케줄러

작업 내용 (설계 의도)

변경 사항

  • PriceAlertScheduler(@Scheduled fixedRate)가 평가 UseCase를 호출.
  • ACTIVE 알림 일괄 평가 → 도달 시 발송 1회 + 이력 적재 + TRIGGERED 전이.
  • STK1-03(도메인)·STK1-04(채널)을 와이어업하는 통합 티켓.

의존

  • 선행: STK1-03, STK1-04
  • 후행: 없음

롤백

  • 폴링 프로퍼티(alert.polling) OFF.

다이어그램

처리 흐름

sequenceDiagram
    participant Scheduler as PriceAlertScheduler
    participant UC as EvaluateAlertsUseCase
    participant DS as PriceAlertDomainService
    participant PGW as PriceGateway
    participant NGW as NotificationGateway
    participant Repo as AlertRepository

    Scheduler->>UC: poll() (30초 fixedRate)
    UC->>DS: evaluateActiveAlerts()
    DS->>Repo: findAllActive()
    alt ACTIVE 알림 없음
        Repo-->>DS: 빈 목록
        DS-->>UC: 종료 (PriceGateway 미호출)
    else ACTIVE 알림 있음
        Repo-->>DS: alerts
        DS->>PGW: getPrices(symbols)
        PGW-->>DS: prices
        loop 도달한 알림
            DS->>NGW: notify(message)
            DS->>Repo: save(TRIGGERED + AlertHistory)
        end
    end
    Note over Scheduler: 예외 발생 시 로그 후 다음 주기 계속

클래스 의존

flowchart LR
    subgraph Presentation["presentation"]
        SCH[PriceAlertScheduler]
    end
    subgraph Application["application"]
        UC[EvaluateAlertsUseCase]
    end
    subgraph Domain["domain"]
        DS[PriceAlertDomainService]
    end
    SCH --> UC
    UC --> DS

테스트 케이스

  • ACTIVE 상태 알림이 목표가에 도달하면 TRIGGERED로 전이되고 알림이 발송된다.
  • TRIGGERED로 전이된 알림은 다음 주기에 평가 대상에 포함되지 않는다.
  • ACTIVE 알림이 없으면 PriceGateway를 호출하지 않는다.
  • 폴링 중 PriceGateway에서 예외가 발생해도 스케줄러가 중단되지 않고 다음 주기를 실행한다.
  • 알림 N개 중 일부만 도달 시 도달한 것만 TRIGGERED로 전이되고 나머지는 ACTIVE를 유지한다.