Skip to content

Commit

Permalink
Merge pull request #173 from cmeyer90/fix-plotman-archive-command
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky authored Apr 27, 2021
2 parents 11921d7 + 65d8a4a commit 8cb707d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
28 changes: 28 additions & 0 deletions src/plotman/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@

# TODO : write-protect and delete-protect archived plots

def spawn_archive_process(dir_cfg, all_jobs):
'''Spawns a new archive process using the command created
in the archive() function. Returns archiving status and a log message to print.'''

log_message = None
archiving_status = None

# Look for running archive jobs. Be robust to finding more than one
# even though the scheduler should only run one at a time.
arch_jobs = get_running_archive_jobs(dir_cfg.archive)

if arch_jobs:
archiving_status = 'pid: ' + ', '.join(map(str, arch_jobs))
else:
(should_start, status_or_cmd) = archive(dir_cfg, all_jobs)
if not should_start:
archiving_status = status_or_cmd
else:
cmd = status_or_cmd
# TODO: do something useful with output instead of DEVNULL
p = subprocess.Popen(cmd,
shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
start_new_session=True)
log_message = 'Starting archive: ' + cmd
return archiving_status, log_message

def compute_priority(phase, gb_free, n_plots):
# All these values are designed around dst buffer dirs of about
# ~2TB size and containing k32 plots. TODO: Generalize, and
Expand Down
22 changes: 3 additions & 19 deletions src/plotman/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,9 @@ def curses_main(stdscr):

if archiving_configured:
if archiving_active:
# Look for running archive jobs. Be robust to finding more than one
# even though the scheduler should only run one at a time.
arch_jobs = archive.get_running_archive_jobs(cfg.directories.archive)
if arch_jobs:
archiving_status = 'pid: ' + ', '.join(map(str, arch_jobs))
else:
(should_start, status_or_cmd) = archive.archive(cfg.directories, jobs)
if not should_start:
archiving_status = status_or_cmd
else:
cmd = status_or_cmd
log.log('Starting archive: ' + cmd)

# TODO: do something useful with output instead of DEVNULL
p = subprocess.Popen(cmd,
shell=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
start_new_session=True)
archiving_status, log_message = archive.spawn_archive_process(cfg.directories, jobs)
if log_message:
log.log(log_message)

archdir_freebytes = archive.get_archdir_freebytes(cfg.directories.archive)

Expand Down
6 changes: 5 additions & 1 deletion src/plotman/plotman.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ def main():
time.sleep(60)
jobs = Job.get_running_jobs(cfg.directories.log)
firstit = False
archive.archive(cfg.directories, jobs)

archiving_status, log_message = archive.spawn_archive_process(cfg.directories, jobs)
if log_message:
print(log_message)


# Debugging: show the destination drive usage schedule
elif args.cmd == 'dsched':
Expand Down

0 comments on commit 8cb707d

Please sign in to comment.