3232
3333@inject
3434async def get_execution_with_access (
35- execution_id : Annotated [str , Path ()],
36- current_user : Annotated [User , Depends (current_user )],
37- execution_service : FromDishka [ExecutionService ],
35+ execution_id : Annotated [str , Path ()],
36+ current_user : Annotated [User , Depends (current_user )],
37+ execution_service : FromDishka [ExecutionService ],
3838) -> ExecutionInDB :
3939 domain_exec = await execution_service .get_execution_result (execution_id )
4040
@@ -50,22 +50,24 @@ async def get_execution_with_access(
5050 responses = {500 : {"model" : ErrorResponse , "description" : "Script execution failed" }},
5151)
5252async def create_execution (
53- request : Request ,
54- current_user : Annotated [User , Depends (current_user )],
55- execution : ExecutionRequest ,
56- execution_service : FromDishka [ExecutionService ],
57- idempotency_key : Annotated [str | None , Header (alias = "Idempotency-Key" )] = None ,
53+ request : Request ,
54+ current_user : Annotated [User , Depends (current_user )],
55+ execution : ExecutionRequest ,
56+ execution_service : FromDishka [ExecutionService ],
57+ idempotency_key : Annotated [str | None , Header (alias = "Idempotency-Key" )] = None ,
5858) -> ExecutionResponse :
5959 """Submit a script for execution in an isolated Kubernetes pod."""
60- trace .get_current_span ().set_attributes ({
61- "http.method" : "POST" ,
62- "http.route" : "/api/v1/execute" ,
63- "execution.language" : execution .lang ,
64- "execution.language_version" : execution .lang_version ,
65- "execution.script_length" : len (execution .script ),
66- "user.id" : current_user .user_id ,
67- "client.address" : get_client_ip (request ),
68- })
60+ trace .get_current_span ().set_attributes (
61+ {
62+ "http.method" : "POST" ,
63+ "http.route" : "/api/v1/execute" ,
64+ "execution.language" : execution .lang ,
65+ "execution.language_version" : execution .lang_version ,
66+ "execution.script_length" : len (execution .script ),
67+ "user.id" : current_user .user_id ,
68+ "client.address" : get_client_ip (request ),
69+ }
70+ )
6971
7072 exec_result = await execution_service .execute_script_idempotent (
7173 script = execution .script ,
@@ -83,7 +85,7 @@ async def create_execution(
8385 responses = {403 : {"model" : ErrorResponse , "description" : "Not the owner of this execution" }},
8486)
8587async def get_result (
86- execution : Annotated [ExecutionInDB , Depends (get_execution_with_access )],
88+ execution : Annotated [ExecutionInDB , Depends (get_execution_with_access )],
8789) -> ExecutionResult :
8890 """Retrieve the result of a specific execution."""
8991 return ExecutionResult .model_validate (execution )
@@ -98,10 +100,10 @@ async def get_result(
98100 },
99101)
100102async def cancel_execution (
101- execution : Annotated [ExecutionInDB , Depends (get_execution_with_access )],
102- current_user : Annotated [User , Depends (current_user )],
103- cancel_request : CancelExecutionRequest ,
104- execution_service : FromDishka [ExecutionService ],
103+ execution : Annotated [ExecutionInDB , Depends (get_execution_with_access )],
104+ current_user : Annotated [User , Depends (current_user )],
105+ cancel_request : CancelExecutionRequest ,
106+ execution_service : FromDishka [ExecutionService ],
105107) -> CancelResponse :
106108 """Cancel a running or queued execution."""
107109 result = await execution_service .cancel_execution (
@@ -122,9 +124,9 @@ async def cancel_execution(
122124 },
123125)
124126async def retry_execution (
125- original_execution : Annotated [ExecutionInDB , Depends (get_execution_with_access )],
126- current_user : Annotated [User , Depends (current_user )],
127- execution_service : FromDishka [ExecutionService ],
127+ original_execution : Annotated [ExecutionInDB , Depends (get_execution_with_access )],
128+ current_user : Annotated [User , Depends (current_user )],
129+ execution_service : FromDishka [ExecutionService ],
128130) -> ExecutionResponse :
129131 """Retry a failed or completed execution."""
130132
@@ -146,10 +148,10 @@ async def retry_execution(
146148 responses = {403 : {"model" : ErrorResponse , "description" : "Not the owner of this execution" }},
147149)
148150async def get_execution_events (
149- execution : Annotated [ExecutionInDB , Depends (get_execution_with_access )],
150- event_service : FromDishka [EventService ],
151- event_types : Annotated [list [EventType ] | None , Query (description = "Event types to filter" )] = None ,
152- limit : Annotated [int , Query (ge = 1 , le = 1000 )] = 100 ,
151+ execution : Annotated [ExecutionInDB , Depends (get_execution_with_access )],
152+ event_service : FromDishka [EventService ],
153+ event_types : Annotated [list [EventType ] | None , Query (description = "Event types to filter" )] = None ,
154+ limit : Annotated [int , Query (ge = 1 , le = 1000 )] = 100 ,
153155) -> list [DomainEvent ]:
154156 """Get all events for an execution."""
155157 events = await event_service .get_events_by_execution_id (
@@ -160,14 +162,14 @@ async def get_execution_events(
160162
161163@router .get ("/user/executions" , response_model = ExecutionListResponse )
162164async def get_user_executions (
163- current_user : Annotated [User , Depends (current_user )],
164- execution_service : FromDishka [ExecutionService ],
165- status : Annotated [ExecutionStatus | None , Query (description = "Filter by execution status" )] = None ,
166- lang : Annotated [str | None , Query (description = "Filter by programming language" )] = None ,
167- start_time : Annotated [datetime | None , Query (description = "Filter executions created after this time" )] = None ,
168- end_time : Annotated [datetime | None , Query (description = "Filter executions created before this time" )] = None ,
169- limit : Annotated [int , Query (ge = 1 , le = 200 )] = 50 ,
170- skip : Annotated [int , Query (ge = 0 )] = 0 ,
165+ current_user : Annotated [User , Depends (current_user )],
166+ execution_service : FromDishka [ExecutionService ],
167+ status : Annotated [ExecutionStatus | None , Query (description = "Filter by execution status" )] = None ,
168+ lang : Annotated [str | None , Query (description = "Filter by programming language" )] = None ,
169+ start_time : Annotated [datetime | None , Query (description = "Filter executions created after this time" )] = None ,
170+ end_time : Annotated [datetime | None , Query (description = "Filter executions created before this time" )] = None ,
171+ limit : Annotated [int , Query (ge = 1 , le = 200 )] = 50 ,
172+ skip : Annotated [int , Query (ge = 0 )] = 0 ,
171173) -> ExecutionListResponse :
172174 """Get executions for the current user."""
173175
@@ -194,7 +196,7 @@ async def get_user_executions(
194196
195197@router .get ("/example-scripts" , response_model = ExampleScripts )
196198async def get_example_scripts (
197- execution_service : FromDishka [ExecutionService ],
199+ execution_service : FromDishka [ExecutionService ],
198200) -> ExampleScripts :
199201 """Get example scripts for the code editor."""
200202 scripts = await execution_service .get_example_scripts ()
@@ -203,7 +205,7 @@ async def get_example_scripts(
203205
204206@router .get ("/k8s-limits" , response_model = ResourceLimits )
205207async def get_k8s_resource_limits (
206- execution_service : FromDishka [ExecutionService ],
208+ execution_service : FromDishka [ExecutionService ],
207209) -> ResourceLimits :
208210 """Get Kubernetes resource limits for script execution."""
209211 limits = await execution_service .get_k8s_resource_limits ()
@@ -212,9 +214,9 @@ async def get_k8s_resource_limits(
212214
213215@router .delete ("/executions/{execution_id}" , response_model = DeleteResponse )
214216async def delete_execution (
215- execution_id : str ,
216- admin : Annotated [User , Depends (admin_user )],
217- execution_service : FromDishka [ExecutionService ],
217+ execution_id : str ,
218+ admin : Annotated [User , Depends (admin_user )],
219+ execution_service : FromDishka [ExecutionService ],
218220) -> DeleteResponse :
219221 """Delete an execution and its associated data (admin only)."""
220222 await execution_service .delete_execution (execution_id , admin .user_id )
0 commit comments