Skip to content

Commit

Permalink
Reworked database more
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Nov 4, 2022
1 parent ed15044 commit 1e80c6e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "RemoteHPC"
uuid = "c4f2a1c4-7655-40d8-82ee-c6ae0a8b7409"
authors = ["louisponet <[email protected]>"]
version = "0.1.2"
version = "0.1.3"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
21 changes: 16 additions & 5 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ api_readdir(req::HTTP.Request) = readdir(path(req))
api_mtime(req::HTTP.Request) = mtime(path(req))
api_filesize(req::HTTP.Request) = filesize(path(req))
api_realpath(req::HTTP.Request) = realpath(path(req))
api_mkpath(req::HTTP.Request) = mkpath(path(req))
api_cp(req::HTTP.Request) = cp(JSON3.read(req.body, Tuple{String, String})...; force=true)

function execute_function(req::HTTP.Router)
funcstr = Meta.parse(path(req))
Expand All @@ -43,7 +45,9 @@ function setup_core_api!(router::HTTP.Router)
HTTP.register!(router, "GET", "/api/**", execute_function)
HTTP.register!(router, "POST", "/write/**", api_write)
HTTP.register!(router, "POST", "/rm/**", api_rm)
return HTTP.register!(router, "POST", "/symlink/", api_symlink)
HTTP.register!(router, "POST", "/symlink/", api_symlink)
HTTP.register!(router, "POST", "/mkpath/**", api_mkpath)
HTTP.register!(router, "POST", "/cp/", api_cp)
end

submit_job(req, channel) = put!(channel, path(req))
Expand All @@ -54,6 +58,7 @@ function get_job(req::HTTP.Request, queue::Queue)
if info === nothing
info = get(queue.info.full_queue, job_dir, nothing)
end
info = info === nothing ? Job(-1, Unknown) : info
tquery = HTTP.queryparams(URI(req.target))
if isempty(tquery) || !haskey(tquery, "data")
return [info,
Expand All @@ -70,11 +75,17 @@ function get_job(req::HTTP.Request, queue::Queue)
elseif d == "state"
push!(out, info.state)
elseif d == "name"
push!(out, jinfo[1])
if jinfo !== nothing
push!(out, jinfo[1])
end
elseif d == "environment"
push!(out, jinfo[2])
if jinfo !== nothing
push!(out, jinfo[2])
end
elseif d == "calculations"
push!(out, jinfo[3])
if jinfo !== nothing
push!(out, jinfo[3])
end
end
end
return out
Expand Down Expand Up @@ -171,7 +182,7 @@ function save(req::HTTP.Request)
end

function database_rm(req)
p = config_path(strip(req.target, '/'))
p = config_path(strip(req.target, '/')) * ".json"
ispath(p)
return rm(p)
end
Expand Down
8 changes: 8 additions & 0 deletions src/servers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ function Base.write(s::Server, path::String, v)
return JSON3.read(resp.body, Int)
end
end
function Base.mkpath(s::Server, dir)
HTTP.post(s, URI(path="/mkpath/" * dir))
return dir
end
function Base.cp(s::Server, src, dst)
HTTP.post(s, URI(path="/cp/"), (src, dst))
return dst
end

parse_config(config) = JSON3.read(config, Server)
read_config(config_file) = parse_config(read(config_file, String))
Expand Down

2 comments on commit 1e80c6e

@louisponet
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/71643

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.3 -m "<description of version>" 1e80c6eefe01a8ad5f84f30d5dea8d42465f6acd
git push origin v0.1.3

Please sign in to comment.