Skip to content

Commit

Permalink
Shutdown noninteractive notebook processes after export (take 2) (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrekker committed Jun 20, 2023
1 parent 1827586 commit 888492c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/Actions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ function process(
end

keep_running =
settings.SliderServer.enabled && !is_glob_match(path, settings.SliderServer.exclude)
settings.SliderServer.enabled &&
!is_glob_match(path, settings.SliderServer.exclude) &&
occursin("@bind", jl_contents)
skip_cache = keep_running || is_glob_match(path, settings.Export.ignore_cache)

cached_state = skip_cache ? nothing : try_fromcache(settings.Export.cache_dir, new_hash)
Expand Down
6 changes: 5 additions & 1 deletion src/HTTPRouter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import JSON

@from "./IndexJSON.jl" import generate_index_json
@from "./IndexHTML.jl" import temp_index, generate_basic_index_html
@from "./Types.jl" import NotebookSession, RunningNotebook
@from "./Types.jl" import NotebookSession, RunningNotebook, FinishedNotebook
@from "./Configuration.jl" import PlutoDeploySettings, get_configuration
@from "./PlutoHash.jl" import base64urldecode

Expand Down Expand Up @@ -189,6 +189,10 @@ function make_router(
HTTP.Response(503, "Still loading the notebooks... check back later!") |>
with_cors! |>
with_not_cacheable!
elseif sesh isa NotebookSession{<:Any,String,FinishedNotebook}
HTTP.Response(422, "Notebook is no longer running") |>
with_cors! |>
with_not_cacheable!
else
HTTP.Response(404, "Not found!") |> with_cors! |> with_not_cacheable!
end
Expand Down
22 changes: 15 additions & 7 deletions test/HTTP requests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ make_test_dir() =
s_a = find(s -> occursin("a.jl", s.path), notebook_sessions)
s_export_only = find(s -> occursin("export_only", s.path), notebook_sessions)

response =
HTTP.request("GET", "http://localhost:$(port)/bondconnections/$(s_a.current_hash)/")
data = Pluto.unpack(response.body)

@test data isa Dict
@test isempty(data) # these notebooks don't have any bonds
response = HTTP.request(
"GET",
"http://localhost:$(port)/bondconnections/$(s_a.current_hash)/";
status_exception=false,
)
@test response.status == 422 # notebook is no longer running since it has no bonds

@test s_export_only.run isa PlutoSliderServer.var"../Types.jl".FinishedNotebook

Expand All @@ -195,7 +195,15 @@ make_test_dir() =
status_exception=false,
)

@test response_export_only.status == 404 # this notebook is not in the slider server
@test response_export_only.status == 422 # this notebook is not in the slider server but was exported

response_no_notebook = HTTP.request(
"GET",
"http://localhost:$(port)/bondconnections/$(plutohash("abc"))/";
status_exception=false,
)

@test response_no_notebook.status == 404 # this notebook is not in the slider server

asset_urls = [
""
Expand Down

0 comments on commit 888492c

Please sign in to comment.