From 06e6b3851016663f421f790de5dfea199a33315b Mon Sep 17 00:00:00 2001 From: JinZhou5042 <142265839+JinZhou5042@users.noreply.github.com> Date: Thu, 6 Feb 2025 08:06:35 -0500 Subject: [PATCH] vine: a manager argument to rename runtime directory (#4041) * add run_info_dir * vine: rename runtime_info_path to runtime_info_template * vine: check if the template has exists * lint * set info template with api * update python * update param name --------- Co-authored-by: Benjamin Tovar --- .../python3/ndcctools/taskvine/manager.py | 19 +++++------ taskvine/src/manager/taskvine.h | 5 +++ taskvine/src/manager/vine_runtime_dir.c | 34 +++++++++++-------- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/taskvine/src/bindings/python3/ndcctools/taskvine/manager.py b/taskvine/src/bindings/python3/ndcctools/taskvine/manager.py index 1aca9c3723..a56abd9c4e 100644 --- a/taskvine/src/bindings/python3/ndcctools/taskvine/manager.py +++ b/taskvine/src/bindings/python3/ndcctools/taskvine/manager.py @@ -65,7 +65,8 @@ class Manager(object): # @param port The port number to listen on. If zero, then a random port is chosen. A range of possible ports (low, hight) can be also specified instead of a single integer. Default is 9123 # @param name The project name to use. # @param shutdown Automatically shutdown workers when manager is finished. Disabled by default. - # @param run_info_path Directory to write log (and staging if staging_path not given) files per run. If None, defaults to "vine-run-info" + # @param run_info_path Directory to archive workflow log directories, it is the upper level directory to run_info_template. If None, defaults to "vine-run-info" + # @param run_info_template See run_info_path. If None, defaults by a %Y-%m-%dT%H%M%S format. # @param staging_path Directory to write temporary files. Defaults to run_info_path if not given. # @param ssl A tuple of filenames (ssl_key, ssl_cert) in pem format, or True. # If not given, then TSL is not activated. If True, a self-signed temporary key and cert are generated. @@ -78,6 +79,7 @@ def __init__(self, name=None, shutdown=False, run_info_path="vine-run-info", + run_info_template=None, staging_path=None, ssl=None, init_fn=None, @@ -111,8 +113,13 @@ def __init__(self, self._info_widget = JupyterDisplay(interval=status_display_interval) try: + # Set an internal variable in the C code. + # No need to unset it explicitly as it doesn't rely on environment variables. if run_info_path: - self.set_runtime_info_path(run_info_path) + cvine.vine_set_runtime_info_path(run_info_path) + + if run_info_template: + cvine.vine_set_runtime_info_template(run_info_template) self._stats = cvine.vine_stats() self._stats_hierarchy = cvine.vine_stats() @@ -554,14 +561,6 @@ def set_catalog_servers(self, catalogs): def set_property(self, name, value): cvine.vine_set_property(self._taskvine, name, value) - ## - # Specify a directory to write logs and staging files. - # - # @param self Reference to the current manager object. - # @param dirname A directory name - def set_runtime_info_path(self, dirname): - cvine.vine_set_runtime_info_path(dirname) - ## # Add a mandatory password that each worker must present. # diff --git a/taskvine/src/manager/taskvine.h b/taskvine/src/manager/taskvine.h index b76869de46..627875a82f 100644 --- a/taskvine/src/manager/taskvine.h +++ b/taskvine/src/manager/taskvine.h @@ -1499,6 +1499,11 @@ void vine_initialize_categories(struct vine_manager *m, struct rmsummary *max, c */ void vine_set_runtime_info_path(const char *path); +/** Sets the directory where a workflow-specific runtime logs are directly written into. +@param dir A directory +*/ +void vine_set_runtime_info_template(const char *template); + /** Adds a custom APPLICATION entry to the debug log. @param m Reference to the current manager object. @param entry A custom debug message. diff --git a/taskvine/src/manager/vine_runtime_dir.c b/taskvine/src/manager/vine_runtime_dir.c index 580149af91..e595307524 100644 --- a/taskvine/src/manager/vine_runtime_dir.c +++ b/taskvine/src/manager/vine_runtime_dir.c @@ -20,6 +20,7 @@ See the file COPYING for details. #include "xxmalloc.h" static char *vine_runtime_info_path = "vine-run-info"; +static char *vine_runtime_info_template = "%Y-%m-%dT%H%M%S"; static struct list *known_staging_dirs = NULL; @@ -58,10 +59,12 @@ char *vine_runtime_directory_create() /* runtime directories are created at vine_runtime_info_path, which defaults * to "vine-run-info" of the current working directory. * Each workflow run has its own directory of the form: %Y-%m-%dT%H%M%S, - * but this can be changed with VINE_RUNTIME_INFO_DIR. + * but this can be changed with vine_set_runtime_info_template(...). * - * If VINE_RUNTIME_INFO_DIR is not an absolute path, then it is - * interpreted as a suffix to vine_runtime_info_path. + * If the value set by vine_runtime_info_template(...) is not an absolute path, then it is + * interpreted as a suffix to vine_set_runtime_info_path. + * + * The value of the directory created is setenv to VINE_RUNTIME_INFO_DIR. * * VINE_RUNTIME_INFO_DIR has the subdirectories: logs and staging * @@ -71,17 +74,14 @@ char *vine_runtime_directory_create() char *runtime_dir = NULL; int symlink_most_recent = 0; - if (getenv("VINE_RUNTIME_INFO_DIR")) { - runtime_dir = xxstrdup(getenv("VINE_RUNTIME_INFO_DIR")); - } else { - char buf[20]; - time_t now = time(NULL); - struct tm *tm_info = localtime(&now); - strftime(buf, sizeof(buf), "%Y-%m-%dT%H%M%S", tm_info); - runtime_dir = xxstrdup(buf); - - symlink_most_recent = 1; - } + + char buf[20]; + time_t now = time(NULL); + struct tm *tm_info = localtime(&now); + strftime(buf, sizeof(buf), vine_runtime_info_template, tm_info); + runtime_dir = xxstrdup(buf); + + symlink_most_recent = 1; if (strncmp(runtime_dir, "/", 1)) { char *tmp = path_concat(vine_runtime_info_path, runtime_dir); @@ -163,3 +163,9 @@ void vine_set_runtime_info_path(const char *path) assert(path); vine_runtime_info_path = xxstrdup(path); } + +void vine_set_runtime_info_template(const char *template) +{ + assert(template); + vine_runtime_info_template = xxstrdup(template); +}