Skip to content

Commit

Permalink
interactive job cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Jun 14, 2021
1 parent 8d2b416 commit 1464023
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/API.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ include("jobAPI.jl")
#Basic Job Control Functionality
export save, submit, abort, set_flow!, set_headerword!, isrunning, progressreport,
set_serverdir!, set_localdir!, structure, scale_cell!, volume,
switch_version, version, versions, registered_jobs, rm_version!, rm_versions!, rm_tmp_dirs!
switch_version, version, versions, registered_jobs, rm_version!, rm_versions!, rm_tmp_dirs!,
cleanup

#Basic Interaction with DFInputs inside DFJob
export searchinput, searchinputs, set_cutoffs!
Expand Down
34 changes: 31 additions & 3 deletions src/job.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,41 @@ function isrunning(job::DFJob; print=true)
return false
end

"Total filesize on disk for a job and all its versions."
function Base.filesize(job::DFJob)
function dirsize(path::String)
totsize = 0.0
for (root, dirs, files) in walkdir(job.local_dir)
for (root, dirs, files) in walkdir(path)
for file in files
totsize += filesize(root, file)
end
end
return totsize
end

"Total filesize on disk for a job and all its versions."
Base.filesize(job::DFJob) = dirsize(job.local_dir)

"Cleanup job files interactively."
function cleanup(job::DFJob)
labels = String[]
paths = String[]
for v in versions(job)
vpath = version_path(job, v)
s = round(dirsize(vpath)/1e6, digits=3)
push!(labels, "Version $v: $s Mb")
push!(paths, vpath)
opath = joinpath(vpath, "outputs")
if ispath(opath)
s_out = round(dirsize(opath)/1e6, digits=3)
push!(labels, "Version $v/outputs: $s_out Mb")
push!(paths, opath)
end
end
menu = MultiSelectMenu(labels)
choices = request("Select job files to delete:", menu)
for i in choices
if ispath(paths[i]) # Could be that outputs was already deleted
@info "Deleting $(paths[i])"
rm(paths[i], recursive=true)
end
end
end

0 comments on commit 1464023

Please sign in to comment.