50 lines
2.1 KiB
Markdown
50 lines
2.1 KiB
Markdown
# DB 기반 동적 스케줄러 관리 시스템
|
|
|
|
**날짜**: 2026-01-02
|
|
**작성자**: happybell80
|
|
**관련 서비스**: rb8001
|
|
**상태**: 구현 완료 (Phase 1-7)
|
|
|
|
→ 상세: [troubleshooting/260102_db_scheduler_management.md](../../troubleshooting/260102_db_scheduler_management.md)
|
|
|
|
---
|
|
|
|
## 목적
|
|
main.py 732줄 중 130줄이 스케줄 관련 코드. DB로 이동하여 동적 관리.
|
|
|
|
## 테이블 구조
|
|
|
|
```sql
|
|
CREATE TABLE IF NOT EXISTS scheduled_jobs (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
name VARCHAR(100) UNIQUE NOT NULL,
|
|
job_type VARCHAR(50) NOT NULL,
|
|
cron_expression VARCHAR(50) NOT NULL,
|
|
enabled BOOLEAN DEFAULT true,
|
|
config JSONB DEFAULT '{}',
|
|
created_at TIMESTAMPTZ DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ DEFAULT NOW()
|
|
);
|
|
```
|
|
|
|
## Job Type 매핑
|
|
|
|
| job_type | 함수 경로 | 비고 |
|
|
|----------|----------|------|
|
|
| `lunch_worldcup` | `app.scheduler.jobs.lunch_worldcup._run_worldcup_with_logging` | sync 래퍼 |
|
|
| `diary_generator` | `app.scheduler.jobs.diary_generator._run_diary_generator_with_logging` | sync 래퍼 |
|
|
| `naverworks_briefing` | `app.scheduler.jobs.naverworks_briefing._run_briefing_with_logging` | sync 래퍼 |
|
|
| `coldmail_briefing` | `app.scheduler.jobs.coldmail_briefing._run_coldmail_briefing_with_logging` | sync 래퍼 |
|
|
| `daily_headlines` | `app.scheduler.jobs.daily_headlines._run_headlines_with_logging` | sync 래퍼, channel_id config 필요 |
|
|
| `companyx_news` | `app.scheduler.jobs.companyx_news._run_companyx_news_with_logging` | sync 래퍼 |
|
|
|
|
## 구현 완료 (Phase 1-7)
|
|
|
|
- Phase 1-2: `app/state/scheduler_repository.py` - CRUD 함수
|
|
- Phase 3: `app/scheduler/db_loader.py` - DB 로더
|
|
- Phase 4: `main.py:146-149` - DB 기반 로드로 전환
|
|
- Phase 5: `app/router/scheduler_endpoint.py` - API 엔드포인트
|
|
- Phase 6: `scripts/migrate_schedules_to_db.py` - 기존 데이터 마이그레이션 (6개 스케줄러: daily_diary, naverworks_daily, coldmail_daily, lunch_worldcup, daily_headlines, companyx_news)
|
|
- Phase 7: Pydantic Settings 전환 - `app/core/config.py`에 스케줄러 설정 추가, `os.getenv()` 제거
|
|
|