@@ -12,7 +12,7 @@ const CORS_HEADERS = [
12
12
]
13
13
14
14
function cors_handler (handler)
15
- return function (req:: HTTP.Request )
15
+ return function (req:: HTTP.Request )
16
16
if HTTP. method (req) == " OPTIONS"
17
17
return HTTP. Response (200 , CORS_HEADERS)
18
18
else
25
25
26
26
function health_check_handler (req:: HTTP.Request )
27
27
@info " Health check ping (backend reachable)"
28
- return HTTP. Response (200 , [" Content-Type" => " application/json" ], JSON3. write (Dict (" status" => " ok" )))
28
+ return HTTP. Response (
29
+ 200 ,
30
+ [" Content-Type" => " application/json" ],
31
+ JSON3. write (Dict (" status" => " ok" )),
32
+ )
29
33
end
30
34
31
35
32
36
function run_model_handler (req:: HTTP.Request )
33
37
logs = String[]
34
38
log! (logs, " Received /api/run request" )
35
39
log! (logs, " Backend processing started." )
36
-
40
+
37
41
tmp_dir = mktempdir ()
38
42
log! (logs, " Created temporary working directory at: $(tmp_dir) " )
39
43
@@ -217,12 +221,17 @@ function run_model_handler(req::HTTP.Request)
217
221
cmd = ` $(julia_executable) --project=$(project_dir) --threads=auto $(script_path) `
218
222
219
223
log! (logs, " Executing script in worker process..." )
220
- timeout_s = try Int (get (settings, :timeout_s , 0 )) catch ; 0 end
224
+ timeout_s = try
225
+ Int (get (settings, :timeout_s , 0 ))
226
+ catch
227
+ ;
228
+ 0
229
+ end
221
230
if timeout_s <= 0
222
231
run (cmd)
223
232
log! (logs, " Script execution finished." )
224
233
else
225
- proc = run (cmd; wait= false )
234
+ proc = run (cmd; wait = false )
226
235
log! (logs, " Worker process started; enforcing timeout of $(timeout_s) s" )
227
236
deadline = time () + timeout_s
228
237
while process_running (proc) && time () < deadline
@@ -258,21 +267,33 @@ function run_model_handler(req::HTTP.Request)
258
267
Dict (" name" => " payload.json" , " content" => read (payload_path, String)),
259
268
]
260
269
if isfile (results_path)
261
- push! (files_arr, Dict (" name" => " results.json" , " content" => read (results_path, String)))
270
+ push! (
271
+ files_arr,
272
+ Dict (" name" => " results.json" , " content" => read (results_path, String)),
273
+ )
262
274
end
263
275
264
276
# Diagnostics: log attachment sizes
265
277
sizes = String[]
266
278
for f in files_arr
267
- push! (sizes, string (f[" name" ], " =" , sizeof (f[" content" ])) )
279
+ push! (sizes, string (f[" name" ], " =" , sizeof (f[" content" ])))
268
280
end
269
- log! (logs, " Attaching $(length (files_arr)) files; sizes(bytes): $(join (sizes, " , " )) " )
281
+ log! (
282
+ logs,
283
+ " Attaching $(length (files_arr)) files; sizes(bytes): $(join (sizes, " , " )) " ,
284
+ )
270
285
271
286
response_body = Dict (
272
287
" success" => true ,
273
- " results" => (haskey (results_content, :summary ) ? results_content[:summary ] : (haskey (results_content, :results ) ? results_content[:results ] : Any[])),
274
- " summary" => (haskey (results_content, :summary ) ? results_content[:summary ] : Any[]),
275
- " quantiles" => (haskey (results_content, :quantiles ) ? results_content[:quantiles ] : Any[]),
288
+ " results" => (
289
+ haskey (results_content, :summary ) ? results_content[:summary ] :
290
+ (haskey (results_content, :results ) ? results_content[:results ] : Any[])
291
+ ),
292
+ " summary" =>
293
+ (haskey (results_content, :summary ) ? results_content[:summary ] : Any[]),
294
+ " quantiles" => (
295
+ haskey (results_content, :quantiles ) ? results_content[:quantiles ] : Any[]
296
+ ),
276
297
" logs" => logs,
277
298
" files" => files_arr,
278
299
)
@@ -293,21 +314,34 @@ function run_model_handler(req::HTTP.Request)
293
314
push! (files_arr, Dict (" name" => " model.bugs" , " content" => model_code))
294
315
end
295
316
if @isdefined (run_script_content)
296
- push! (files_arr, Dict (" name" => " run_script.jl" , " content" => run_script_content))
317
+ push! (
318
+ files_arr,
319
+ Dict (" name" => " run_script.jl" , " content" => run_script_content),
320
+ )
297
321
end
298
322
if @isdefined (payload_path) && isfile (payload_path)
299
- push! (files_arr, Dict (" name" => " payload.json" , " content" => read (payload_path, String)))
323
+ push! (
324
+ files_arr,
325
+ Dict (" name" => " payload.json" , " content" => read (payload_path, String)),
326
+ )
300
327
end
301
328
if @isdefined (results_path) && isfile (results_path)
302
- push! (files_arr, Dict (" name" => " results.json" , " content" => read (results_path, String)))
329
+ push! (
330
+ files_arr,
331
+ Dict (" name" => " results.json" , " content" => read (results_path, String)),
332
+ )
303
333
end
304
334
error_response = Dict (
305
335
" success" => false ,
306
336
" error" => sprint (showerror, e),
307
337
" logs" => logs,
308
338
" files" => files_arr,
309
339
)
310
- return HTTP. Response (500 , [" Content-Type" => " application/json" ], JSON3. write (error_response))
340
+ return HTTP. Response (
341
+ 500 ,
342
+ [" Content-Type" => " application/json" ],
343
+ JSON3. write (error_response),
344
+ )
311
345
finally
312
346
# Clean up temp directory in background with retries to avoid EBUSY on Windows
313
347
@async safe_rmdir (tmp_dir)
@@ -327,11 +361,11 @@ end
327
361
Remove directory tree with retries and backoff. Resilient to transient EBUSY on Windows.
328
362
Intended to be called in a background task.
329
363
"""
330
- function safe_rmdir (path:: AbstractString ; retries:: Int = 6 , sleep_s:: Float64 = 0.25 )
331
- for _ in 1 : retries
364
+ function safe_rmdir (path:: AbstractString ; retries:: Int = 6 , sleep_s:: Float64 = 0.25 )
365
+ for _ = 1 : retries
332
366
try
333
367
GC. gc ()
334
- rm (path; recursive= true , force= true )
368
+ rm (path; recursive = true , force = true )
335
369
return
336
370
catch e
337
371
msg = sprint (showerror, e)
0 commit comments