@cryptotaxi247 / CoPilot / commits / e6b87786

Update provision and scheduler files

Taylor committed Apr 23, 2024 at 11:08 UTC e6b87786488436578457454a02883329f482d6e2
3 files changed +18 -9
backend/app/customer_provisioning/schema/provision.py
+2 -2
@@ -63,8 +63,8 @@ class ProvisionNewCustomer(BaseModel):
63 example={
64 "dashboards": [
65 "WAZUH_SUMMARY",
66 - ]
67 - }
66 + ],
67 + },
68 )
69 wazuh_auth_password: Optional[str] = Field("n/a", description="Password for the Wazuh API user")
70 wazuh_registration_port: Optional[str] = Field(
backend/app/schedulers/routes/scheduler.py
+9 -7
@@ -3,18 +3,17 @@ from typing import Optional
3
4 from fastapi import APIRouter
5 from fastapi import Depends
6 -from datetime import datetime
6 from fastapi import HTTPException
7 from loguru import logger
8 from sqlalchemy.ext.asyncio import AsyncSession
9 from sqlalchemy.future import select
11 -import pytz
10
11 from app.db.db_session import get_db
12 from app.schedulers.models.scheduler import JobMetadata
13 from app.schedulers.scheduler import get_function_by_name
14 from app.schedulers.scheduler import get_scheduler_instance
15 from app.schedulers.scheduler import init_scheduler
16 +from app.schedulers.schema.scheduler import JobsNextRunResponse
17 from app.schedulers.schema.scheduler import JobsResponse
18
19 scheduler_router = APIRouter()
@@ -116,8 +115,9 @@ async def get_all_jobs(session: AsyncSession = Depends(get_db)) -> JobsResponse:
115 message="Jobs successfully retrieved.",
116 )
117
119 -@scheduler_router.get("/next_run/{job_id}")
120 -async def get_next_run(job_id: str):
118 +
119 +@scheduler_router.get("/next_run/{job_id}", response_model=JobsNextRunResponse, description="Get the next run time of a job")
120 +async def get_next_run(job_id: str) -> JobsNextRunResponse:
121 """
122 Get the next run time of a job.
123
@@ -131,11 +131,13 @@ async def get_next_run(job_id: str):
131 job = await find_job_by_id(scheduler, job_id)
132 if job is None:
133 raise HTTPException(status_code=404, detail="Job not found")
134 - now = datetime.now(pytz.utc)
134 next_run_time = job.next_run_time
136 - delta = next_run_time - now
135 logger.info(f"Next run time for job {job_id}: {next_run_time}")
138 - return None
136 + return JobsNextRunResponse(
137 + next_run_time=next_run_time,
138 + success=True,
139 + message="Next run time successfully retrieved.",
140 + )
141
142
143 @scheduler_router.post("/add", description="Add a job")
backend/app/schedulers/schema/scheduler.py
+7
@@ -1,3 +1,4 @@
1 +from datetime import datetime
2 from typing import List
3
4 from pydantic import BaseModel
@@ -14,3 +15,9 @@ class JobsResponse(BaseModel):
15 jobs: List[Job]
16 success: bool
17 message: str
18 +
19 +
20 +class JobsNextRunResponse(BaseModel):
21 + next_run_time: datetime
22 + success: bool
23 + message: str