Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Oct 24, 2022
1 parent 9860468 commit 0a97938
Show file tree
Hide file tree
Showing 15 changed files with 341 additions and 248 deletions.
8 changes: 8 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
style = "yas"
align_assignment = true
whitespace_in_kwargs = true
whitespace_ops_in_indices = false
pipe_to_function_call = false
align_struct_field = true
align_pair_arrow = true
align_conditional = true
20 changes: 20 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: TagBot
on:
issue_comment:
types:
- created
workflow_dispatch:
inputs:
lookback:
default: 3
permissions:
contents: write
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Manifest.toml
21 changes: 13 additions & 8 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ paths = ["jobs",
"storage/servers",
"storage/execs",
"storage/environments"]
for p in paths
for p in paths
mkpath(config_path(p))
end

Expand All @@ -27,26 +27,31 @@ function configure_local()
if !ispath(spath)
scheduler = nothing
if haskey(ENV, "DFC_SCHEDULER")

sched = ENV["DFC_SCHEDULER"]
if occursin("hq", lowercase(sched))
cmd = get(ENV, "DFC_SCHEDULER_CMD", "hq")
scheduler = (type="hq", server_command=cmd, allocs=String[])
scheduler = (type = "hq", server_command = cmd, allocs = String[])
elseif lowercase(sched) == "slurm"
scheduler = (type="slurm",)
scheduler = (type = "slurm",)
else
error("Scheduler $sched not recognized please set a different DFC_SCHEDULER environment var.")
end
end

for t in ("hq", "sbatch")
if Sys.which(t) !== nothing
scheduler = t == "hq" ? (type="hq", server_command="hq", allocs=String[]) : (type="slurm",)
scheduler = t == "hq" ?
(type = "hq", server_command = "hq", allocs = String[]) :
(type = "slurm",)
end
end
scheduler = scheduler === nothing ? (type="bash", ) : scheduler
scheduler = scheduler === nothing ? (type = "bash",) : scheduler
user = get(ENV, "USER", "noname")
JSON3.write(spath, (name=host, username=user, domain="localhost", julia_exec=joinpath(Sys.BINDIR, "julia"), scheduler=scheduler, port=8080, local_port=0, root_jobdir=homedir(), max_concurrent_jobs=100, uuid=string(uuid4())))
JSON3.write(spath,
(name = host, username = user, domain = "localhost",
julia_exec = joinpath(Sys.BINDIR, "julia"), scheduler = scheduler,
port = 8080, local_port = 0, root_jobdir = homedir(),
max_concurrent_jobs = 100, uuid = string(uuid4())))
end
end
configure_local()
8 changes: 3 additions & 5 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Documenter
using RemoteHPC

makedocs(
sitename = "RemoteHPC",
format = Documenter.HTML(),
modules = [RemoteHPC]
)
makedocs(; sitename = "RemoteHPC",
format = Documenter.HTML(),
modules = [RemoteHPC])

# Documenter can also automatically deploy documentation to gh-pages.
# See "Hosting Documentation" and deploydocs() in the Documenter manual
Expand Down
7 changes: 4 additions & 3 deletions src/RemoteHPC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ include("schedulers.jl")
include("servers.jl")
include("runtime.jl")
include("api.jl")
include("client.jl")
include("client.jl")
include("io.jl")

@precompile_all_calls begin
s = local_server()
t = "asdfe"
t2 = "edfasdf"
e = Exec(name = t2, exec="srun")
e1 = Environment(t, Dict("-N" => 3, "partition" => "default", "time" => "00:01:01"), Dict("OMP_NUM_THREADS" => 1), "", "", e)
e = Exec(; name = t2, exec = "srun")
e1 = Environment(t, Dict("-N" => 3, "partition" => "default", "time" => "00:01:01"),
Dict("OMP_NUM_THREADS" => 1), "", "", e)
save(e1)
save(e)
e1 = load(e1)
Expand Down
52 changes: 28 additions & 24 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ get_server_config(req) = local_server()
api_ispath(req::HTTP.Request) = ispath(path(req))
api_read(req::HTTP.Request) = read(path(req))
api_write(req::HTTP.Request) = write(path(req), req.body)
api_rm(req::HTTP.Request) = rm(path(req), recursive=true)
api_rm(req::HTTP.Request) = rm(path(req); recursive = true)
api_symlink(req::HTTP.Request) = symlink(JSON3.read(req.body, Vector{String})...)
api_readdir(req::HTTP.Request) = readdir(path(req))
api_mtime(req::HTTP.Request) = mtime(path(req))
Expand Down Expand Up @@ -45,7 +45,7 @@ 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)
HTTP.register!(router, "POST", "/symlink/", api_symlink)
return HTTP.register!(router, "POST", "/symlink/", api_symlink)
end

submit_job(req, channel) = put!(channel, path(req))
Expand All @@ -55,8 +55,10 @@ function get_job(job_dir::AbstractString, queue::Queue)
if info === nothing
info = get(queue.info.full_queue, job_dir, nothing)
end

return (info, JSON3.read(read(joinpath(job_dir, ".remotehpc_info")), Tuple{String, Environment, Vector{Calculation}})...)

return (info,
JSON3.read(read(joinpath(job_dir, ".remotehpc_info")),
Tuple{String,Environment,Vector{Calculation}})...)
end

function get_jobs(state::JobState, queue::Queue)
Expand All @@ -83,20 +85,21 @@ function get_jobs(dirfuzzy::AbstractString, queue::Queue)
return jobs
end

save_job(req::HTTP.Request, args...) =
save_job(path(req),
JSON3.read(req.body, Tuple{String, Environment, Vector{Calculation}}),
args...)
function save_job(req::HTTP.Request, args...)
return save_job(path(req),
JSON3.read(req.body, Tuple{String,Environment,Vector{Calculation}}),
args...)
end

function save_job(dir::AbstractString, job_info::Tuple, queue::Queue, sched::Scheduler)
function save_job(dir::AbstractString, job_info::Tuple, queue::Queue, sched::Scheduler)
# Needs to be done so the inputs `dir` also changes.
mkpath(dir)
open(joinpath(dir, "job.sh"), "w") do f
write(f, job_info, sched)
return write(f, job_info, sched)
end
JSON3.write(joinpath(dir, ".remotehpc_info"), job_info)
JSON3.write(joinpath(dir, ".remotehpc_info"), job_info)
lock(queue) do q
q.full_queue[dir] = Job(-1, Saved)
return q.full_queue[dir] = Job(-1, Saved)
end
end

Expand All @@ -110,21 +113,23 @@ function abort(req::HTTP.Request, queue::Queue, sched::Scheduler)
lock(queue) do q
j = pop!(q.current_queue, jdir)
j.state = Cancelled
q.full_queue[jdir] = j
return q.full_queue[jdir] = j
end

return j.id
end

function setup_job_api!(router::HTTP.Router, submit_channel, queue::Queue, scheduler::Scheduler)
function setup_job_api!(router::HTTP.Router, submit_channel, queue::Queue,
scheduler::Scheduler)
HTTP.register!(router, "POST", "/job/**", (req) -> save_job(req, queue, scheduler))
HTTP.register!(router, "PUT", "/job/**", (req) -> submit_job(req, submit_channel))
HTTP.register!(router, "GET", "/job/**", (req) -> get_job(path(req), queue))
HTTP.register!(router, "GET", "/jobs/state",
(req) -> get_jobs(JSON3.read(req.body, JobState), queue))
(req) -> get_jobs(JSON3.read(req.body, JobState), queue))
HTTP.register!(router, "GET", "/jobs/fuzzy",
(req) -> get_jobs(JSON3.read(req.body, String), queue))
HTTP.register!(router, "POST", "/abort/**", (req) -> abort(req, queue, scheduler))
(req) -> get_jobs(JSON3.read(req.body, String), queue))
return HTTP.register!(router, "POST", "/abort/**",
(req) -> abort(req, queue, scheduler))
end

function load(req::HTTP.Request)
Expand All @@ -137,13 +142,13 @@ function load(req::HTTP.Request)
try
return load(val)
catch
return map(x->storage_name(x), replacements(val))
return map(x -> storage_name(x), replacements(val))
end
else
cpath = config_path(p)
cpath = config_path(p)
if isempty(splitext(p)[end])
# Here we return the possibilities
return map(x->splitext(x)[1], readdir(cpath))
return map(x -> splitext(x)[1], readdir(cpath))
else
return read(cpath, String)
end
Expand All @@ -165,7 +170,7 @@ end
function database_rm(req)
p = config_path(path(req))
ispath(p)
rm(p)
return rm(p)
end

function name(req)
Expand All @@ -178,6 +183,5 @@ function setup_database_api!(router)
HTTP.register!(router, "GET", "/database/storage/**", load)
HTTP.register!(router, "POST", "/database/storage/**", save)
HTTP.register!(router, "PUT", "/database/storage/**", database_rm)
HTTP.register!(router, "GET", "/database/name", name)
return HTTP.register!(router, "GET", "/database/name", name)
end

Loading

0 comments on commit 0a97938

Please sign in to comment.