Skip to content

Commit

Permalink
feat: Generate random job id in Python quickstarts
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher-Chianelli authored and triceo committed Dec 3, 2024
1 parent 0f7d5de commit 3acdd34
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
10 changes: 6 additions & 4 deletions python/employee-scheduling/src/employee_scheduling/rest_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from uuid import uuid4

from .domain import EmployeeSchedule
from .demo_data import DemoData, generate_demo_data
Expand Down Expand Up @@ -36,10 +37,11 @@ def update_schedule(problem_id: str, schedule: EmployeeSchedule):

@app.post("/schedules")
async def solve_timetable(schedule: EmployeeSchedule) -> str:
data_sets['ID'] = schedule
solver_manager.solve_and_listen('ID', schedule,
lambda solution: update_schedule('ID', solution))
return 'ID'
job_id = str(uuid4())
data_sets[job_id] = schedule
solver_manager.solve_and_listen(job_id, schedule,
lambda solution: update_schedule(job_id, solution))
return job_id


@app.delete("/schedules/{problem_id}")
Expand Down
10 changes: 6 additions & 4 deletions python/school-timetabling/src/school_timetabling/rest_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fastapi import FastAPI, Depends, Request
from fastapi.staticfiles import StaticFiles
from typing import Annotated
from uuid import uuid4

from .domain import *
from .score_analysis import *
Expand Down Expand Up @@ -41,10 +42,11 @@ def update_timetable(problem_id: str, timetable: Timetable):

@app.post("/timetables")
async def solve_timetable(timetable: Timetable) -> str:
data_sets['ID'] = timetable
solver_manager.solve_and_listen('ID', timetable,
lambda solution: update_timetable('ID', solution))
return 'ID'
job_id = str(uuid4())
data_sets[job_id] = timetable
solver_manager.solve_and_listen(job_id, timetable,
lambda solution: update_timetable(job_id, solution))
return job_id


async def setup_context(request: Request) -> Timetable:
Expand Down
10 changes: 6 additions & 4 deletions python/vehicle-routing/src/vehicle_routing/rest_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from fastapi import FastAPI, Depends, Request
from fastapi.staticfiles import StaticFiles
from uuid import uuid4

from .domain import *
from .score_analysis import *
Expand Down Expand Up @@ -74,10 +75,11 @@ async def setup_context(request: Request) -> VehicleRoutePlan:

@app.post("/route-plans")
async def solve_route(route: Annotated[VehicleRoutePlan, Depends(setup_context)]) -> str:
data_sets['ID'] = route
solver_manager.solve_and_listen('ID', route,
lambda solution: update_route('ID', solution))
return 'ID'
job_id = str(uuid4())
data_sets[job_id] = route
solver_manager.solve_and_listen(job_id, route,
lambda solution: update_route(job_id, solution))
return job_id


@app.put("/route-plans/analyze")
Expand Down

0 comments on commit 3acdd34

Please sign in to comment.