Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version to health endpoint #123

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions docker/Dockerfile.api
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ FROM julia:1.9
WORKDIR /sciml-service

# Install SimulationService.jl
ENV JULIA_PROJECT=.
COPY Project.toml /sciml-service/
COPY Manifest.toml /sciml-service/
RUN julia -e 'using Pkg; Pkg.instantiate();'
COPY src/ /sciml-service/src/
COPY examples/ /sciml-service/examples/
ENV JULIA_PROJECT=.
RUN julia -e 'using Pkg; Pkg.instantiate();'

COPY .git/HEAD .git/HEAD
COPY .git/refs .git/refs
RUN grep '^ref:' .git/HEAD && cp .git/`cat .git/HEAD | awk '/^ref: / {print $2}'` .version || cp .git/HEAD /sciml-service/.version
RUN rm -fr .git

# Launch sciml-service
EXPOSE 8080
Expand Down
28 changes: 19 additions & 9 deletions src/SimulationService.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ 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 "/" health
Oxygen.@get "/health" health
Oxygen.@get "/status/{id}" job_status
Oxygen.@post "/kill/{id}" job_kill
Oxygen.@post "/kill/{id}" job_kill

Oxygen.@post "/simulate" req -> operation(req, "simulate")
Oxygen.@post "/calibrate" req -> operation(req, "calibrate")
Oxygen.@post "/ensemble-simulate" req -> operation(req, "ensemble-simulate")
Oxygen.@post "/ensemble-calibrate" req -> operation(req, "ensemble-calibrate")
Oxygen.@post "/ensemble-calibrate" req -> operation(req, "ensemble-calibrate")

# For /docs
Oxygen.mergeschema(openapi_spec[])
Expand Down Expand Up @@ -189,12 +189,22 @@ function job_kill(::HTTP.Request, id::String)
end

#-----------------------------------------------------------------------------# health: GET /
health(::HTTP.Request) = (
status = "ok",
RABBITMQ_ENABLED = RABBITMQ_ENABLED[],
RABBITMQ_ROUTE = RABBITMQ_ROUTE[],
ENABLE_TDS = ENABLE_TDS[]
)
function health(::HTTP.Request)
version_filepath = normpath(joinpath(@__FILE__,"../../.version"))
version =
if ispath(version_filepath)
version_filepath |> strip ∘ String ∘ read ∘ open
else
"unknown"
end
(
status = "ok",
git_sha = version,
RABBITMQ_ENABLED = RABBITMQ_ENABLED[],
RABBITMQ_ROUTE = RABBITMQ_ROUTE[],
ENABLE_TDS = ENABLE_TDS[]
)
end

#-----------------------------------------------------------------------------# OperationRequest
Base.@kwdef mutable struct OperationRequest
Expand Down
Loading