Skip to content

feat: daily scenario generation scheduling at midnight KST#41

Merged
dev-yunseong merged 3 commits intomainfrom
copilot/scheduling-scenario-creation
Mar 17, 2026
Merged

feat: daily scenario generation scheduling at midnight KST#41
dev-yunseong merged 3 commits intomainfrom
copilot/scheduling-scenario-creation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

Implements automated daily scenario generation triggered at 00:00 KST: requests AI server generation, polls for completion, generates images, and assigns the result as the next day's scenario — with up to 5 retries on any failure.

Key changes

  • @EnableScheduling added to MainServerApplication
  • ScenarioDailyScheduler (new component):
    • Fires at 0 0 0 * * * Asia/Seoul via @Scheduled; launches work in a non-blocking CoroutineScope(Dispatchers.IO + SupervisorJob())
    • Also triggers once on server startup via @EventListener(ApplicationReadyEvent::class)
    • Skips generation if a scenario for tomorrow already exists (ScenarioRepository.findByDate check) — prevents duplicate generation on midnight cron or server restart
    • Target date (now + 1 day) captured once before the retry loop — consistent across all attempts regardless of execution duration
    • Polls AiClient.getScenarioCreateTask(key) every 30 s; hard cap of 240 polls (2 h) prevents unbounded execution
    • On COMPLETED: runs ImageGenerationService.generateImagesForScenarioAdminService.updateScenarioDate(tomorrow)
    • On FAILED, poll timeout, or any exception: returns false → outer loop retries up to 5 times
@EventListener(ApplicationReadyEvent::class)
fun onApplicationReady() {
    scope.launch { generateScenarioWithRetry() }
}

@Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul")
fun scheduleScenarioGeneration() {
    scope.launch { generateScenarioWithRetry() }
}
  • ScenarioDailySchedulerTest — 8 unit tests using runTest (virtual time; no real 30 s waits) covering: skip when tomorrow's scenario exists, happy path, retry-then-succeed, max retries exhausted, startGeneration throws, null scenarioId, poll timeout, and poll exception recovery
Original prompt

This section details on the original issue you should resolve

<issue_title>시나리오 생성 scheduling</issue_title>
<issue_description>## 기능 요구 사항

  • 매일 00시에 시나리오 생성을 시작한다.
    • ai 서버에 생성 요청
    • task 30초마다 polling을 해서 생성이 끝났는지 확인
    • 이미지 생성
    • 성공적으로 생성시 다음날 시나리오로 지정
    • 실패시 처음부터 최대 5회 다시 시작</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: dev-yunseong <88422717+dev-yunseong@users.noreply.github.com>
Copilot AI changed the title [WIP] Add scheduling for scenario creation at midnight feat: daily scenario generation scheduling at midnight KST Mar 17, 2026
Copilot AI requested a review from dev-yunseong March 17, 2026 03:55
@dev-yunseong
Copy link
Copy Markdown
Collaborator

@copilot
그리고 서버 켰을 때도 한번 생성을 시도하도록 해줘

@dev-yunseong
Copy link
Copy Markdown
Collaborator

@copilot 내일 날짜로 이미 시나리오가 있으면 생성을 스킵하는 기능도 만들어줘

@Apptive-Game-Team Apptive-Game-Team deleted a comment from Copilot AI Mar 17, 2026
@Apptive-Game-Team Apptive-Game-Team deleted a comment from Copilot AI Mar 17, 2026
…startup

Co-authored-by: dev-yunseong <88422717+dev-yunseong@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 17, 2026

@copilot
그리고 서버 켰을 때도 한번 생성을 시도하도록 해줘

Added in d06da9e via @EventListener(ApplicationReadyEvent::class). It calls the same generateScenarioWithRetry(), so the "already exists" check prevents a double-generation if the server restarts after midnight has already run.

@dev-yunseong dev-yunseong marked this pull request as ready for review March 17, 2026 04:01
@dev-yunseong dev-yunseong merged commit ff1ea7b into main Mar 17, 2026
@dev-yunseong dev-yunseong deleted the copilot/scheduling-scenario-creation branch March 17, 2026 04:01
Copilot stopped work on behalf of dev-yunseong due to an error March 17, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

시나리오 생성 scheduling

2 participants