Skip to content

Commit

Permalink
Error message for failing to create model in model-equation endpoint (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jClugstor authored Sep 24, 2024
1 parent 458854a commit f750b79
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
20 changes: 11 additions & 9 deletions src/SimulationService.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ function start!(; host=HOST[], port=PORT[], kw...)
JobSchedulers.set_scheduler(max_cpu=JobSchedulers.SCHEDULER_MAX_CPU, max_mem=0.5, update_second=0.05, max_job=5000)
Oxygen.resetstate()


Oxygen.@get "/model-equation/{id}" modelEquation
Oxygen.@post "/model-equation" modelToEquation
Oxygen.@get "/model-equation/{id}" model_equation

Oxygen.@get "/health" health
Oxygen.@get "/status/{id}" job_status
Expand Down Expand Up @@ -220,17 +218,21 @@ function job_kill(::HTTP.Request, id::String)
end

# GET /model-equation/{id}
function modelEquation(::HTTP.Request, id::String)
function model_equation(::HTTP.Request, id::String)
@assert ENABLE_TDS[]

tds_url = "$(TDS_URL[])/models/$id"
model_json = JSON3.read(HTTP.get(tds_url, [basic_auth_header[], json_content_header, snake_case_header]).body)
sys = amr_get(model_json, ODESystem)

model_latex = latexify(sys)
return Dict([
(:latex, model_latex.s)
])
try
sys = amr_get(model_json, ODESystem)

model_latex = latexify(sys)
catch ex
error_string = sprint(showerror,ex)
return HTTP.Response(500, "/model-equation failure. Server error: $error_string")
end
return Dict([(:latex, model_latex.s)])
end

# POST /model-equation
Expand Down
14 changes: 7 additions & 7 deletions src/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
# Get `ModelingToolkit.ODESystem` from AMR

function amr_get(amr::JSON3.Object,::Type{ODESystem})
schema_url = amr.header.schema
if contains(schema_url,"petrinet_schema")
schema_url = amr.header.schema
if contains(schema_url,"petrinet_schema")
return amr_get_petrinet(amr)
elseif contains(schema_url, "stockflow_schema")
return amr_get_stockflow(amr)
elseif contains(schema_url,"regnet_schema")
return amr_get_regnet(amr)
end
elseif contains(schema_url, "stockflow_schema")
return amr_get_stockflow(amr)
elseif contains(schema_url,"regnet_schema")
return amr_get_regnet(amr)
end
end

function amr_get_stockflow(amr::JSON3.Object)
Expand Down

0 comments on commit f750b79

Please sign in to comment.