-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
배치 잡 API 개발 및 DependencySolver 수정 (#25)
1. DependencySolver 에서 불필요한 argparse 사용으로 인해 발생하던 "unrecognized arguments" 에러 해결 2. 배치 잡 스케줄러에서 DependencySolver 사용하여 잡 실행하도록 개선 3. 배치 잡 스케줄러 로깅문 강화 4. 배치 잡 리스트/강제실행 API 구현
- Loading branch information
Showing
8 changed files
with
170 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .views import v1_router as router | ||
|
||
__all__ = ["router"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from datetime import datetime, time | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class JobDto(BaseModel): | ||
name: str | ||
interval: int | ||
unit: str | ||
start_day: str | None | ||
at_time: time | None | ||
next_run: datetime | None | ||
last_run: datetime | None | ||
|
||
|
||
class ScheduleResponse(BaseModel): | ||
jobs: list[JobDto] | ||
|
||
|
||
class ForceRunResult(BaseModel): | ||
name: str | ||
tags: list[str] | ||
success: bool | ||
reason: str | None = None | ||
|
||
|
||
class ForceRunResponse(BaseModel): | ||
results: list[ForceRunResult] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from fastapi import APIRouter | ||
|
||
from waffledotcom.src.batch.scheduler import get_job_name, scheduler | ||
|
||
from .schemas import ForceRunResponse, ForceRunResult, JobDto, ScheduleResponse | ||
|
||
v1_router = APIRouter(prefix="/v1/batch", tags=["batch"]) | ||
|
||
|
||
@v1_router.get("/schedule", response_model_exclude_none=True) | ||
def get_schedule( | ||
tag: str | None = None, | ||
) -> ScheduleResponse: | ||
job_dtos = [ | ||
JobDto( | ||
name=getattr(job.job_func, "__qualname__", "Unknown"), | ||
interval=job.interval, | ||
unit=job.unit, # type: ignore | ||
start_day=job.start_day, | ||
at_time=job.at_time, | ||
next_run=job.next_run, | ||
last_run=job.last_run, | ||
) | ||
for job in scheduler.get_jobs(tag) | ||
] | ||
return ScheduleResponse(jobs=job_dtos) | ||
|
||
|
||
@v1_router.post("/force-run", response_model_exclude_none=True) | ||
def force_run_job( | ||
name: str | None = None, | ||
tag: str | None = None, | ||
) -> ForceRunResponse: | ||
if not ((name is None) ^ (tag is None)): | ||
raise ValueError("Either name or tag should be provided") | ||
jobs = scheduler.get_jobs(tag) | ||
if name is not None: | ||
jobs = [job for job in jobs if get_job_name(job) == name] | ||
|
||
results: list[ForceRunResult] = [] | ||
for job in jobs: | ||
try: | ||
job.run() | ||
results.append( | ||
ForceRunResult( | ||
name=get_job_name(job), | ||
tags=list(map(str, job.tags)), | ||
success=True, | ||
) | ||
) | ||
except Exception as e: | ||
results.append( | ||
ForceRunResult( | ||
name=get_job_name(job), | ||
tags=list(map(str, job.tags)), | ||
success=False, | ||
reason=str(e), | ||
) | ||
) | ||
return ForceRunResponse(results=results) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from fastapi.routing import APIRouter | ||
|
||
from waffledotcom.src.apps import user | ||
from waffledotcom.src.apps import batch, user | ||
|
||
api_router = APIRouter(prefix="/api") | ||
api_router.include_router(user.router) | ||
api_router.include_router(batch.router) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters