Skip to content

Commit

Permalink
Don't keep notebooks running if they appear in SliderServer.exclude (#95
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fonsp authored Nov 2, 2022
1 parent 77b2717 commit 0b33755
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
10 changes: 3 additions & 7 deletions src/Actions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ function process(
@warn "Notebook file does not have desired hash. This probably means that the file changed too quickly. Continuing and hoping for the best!" s.path new_hash s.desired_hash
end

keep_running = settings.SliderServer.enabled
keep_running =
settings.SliderServer.enabled && !is_glob_match(path, settings.SliderServer.exclude)
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 Expand Up @@ -114,12 +115,7 @@ function process(

@info "### ✓ $(progress) Ready" s.path new_hash

NotebookSession(;
path=s.path,
current_hash=new_hash,
desired_hash=s.desired_hash,
run=run,
)
NotebookSession(; path, current_hash=new_hash, desired_hash=s.desired_hash, run)
end

###
Expand Down
30 changes: 27 additions & 3 deletions test/HTTP requests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ using UUIDs, Random
PlutoSliderServer.run_directory(
test_dir;
Export_enabled=false,
Export_cache_dir=cache_dir,
SliderServer_port=port,
notebook_paths,
on_ready,
Expand Down Expand Up @@ -119,7 +120,7 @@ using UUIDs, Random
end



find(f, xs) = xs[findfirst(f, xs)]


original_dir1 = joinpath(@__DIR__, "dir1")
Expand All @@ -133,6 +134,15 @@ make_test_dir() =

@testset "HTTP requests: static" begin
test_dir = make_test_dir()
let
# add one more file that we will only export, but not run in the slider server
old = read(joinpath(test_dir, "a.jl"), String)
new = replace(old, "Hello" => "Hello again")
@assert old != new

mkpath(joinpath(test_dir, "x", "y", "z"))
write(joinpath(test_dir, "x", "y", "z", "export_only.jl"), new)
end

port = rand(12345:65000)

Expand All @@ -150,7 +160,9 @@ make_test_dir() =
Export_enabled=true,
Export_baked_notebookfile=false,
Export_baked_state=false,
Export_cache_dir=cache_dir,
SliderServer_port=port,
SliderServer_exclude=["*/export_only*"],
on_ready,
)
end
Expand All @@ -165,14 +177,26 @@ make_test_dir() =



s = notebook_sessions[1]
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.current_hash)/")
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

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

response_export_only = HTTP.request(
"GET",
"http://localhost:$(port)/bondconnections/$(s_export_only.current_hash)/";
status_exception=false,
)

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

asset_urls = [
""
"pluto_export.json"
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ just_run_test_server = false
if just_run_test_server
include("./runtestserver.jl")
else
cache_dir = tempname(cleanup=false)

ENV["HIDE_PLUTO_EXACT_VERSION_WARNING"] = "true"
include("./plutohash.jl")
include("./configuration.jl")
Expand Down
2 changes: 0 additions & 2 deletions test/static export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ make_test_dir() =
new
end

cache_dir = tempname(cleanup=false)

@testset "static - Basic github action" begin
test_dir = make_test_dir()

Expand Down

0 comments on commit 0b33755

Please sign in to comment.