diff --git a/src/plotman/archive.py b/src/plotman/archive.py index 17a29af0..6d9f15f8 100644 --- a/src/plotman/archive.py +++ b/src/plotman/archive.py @@ -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 diff --git a/src/plotman/interactive.py b/src/plotman/interactive.py index d10a2b22..1597bb82 100644 --- a/src/plotman/interactive.py +++ b/src/plotman/interactive.py @@ -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) diff --git a/src/plotman/plotman.py b/src/plotman/plotman.py index 77602d69..2dd34579 100755 --- a/src/plotman/plotman.py +++ b/src/plotman/plotman.py @@ -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':