Skip to content

Commit

Permalink
vine: a manager argument to rename runtime directory (#4041)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
JinZhou5042 and btovar authored Feb 6, 2025
1 parent 1875bd2 commit 06e6b38
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
19 changes: 9 additions & 10 deletions taskvine/src/bindings/python3/ndcctools/taskvine/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
#
Expand Down
5 changes: 5 additions & 0 deletions taskvine/src/manager/taskvine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 20 additions & 14 deletions taskvine/src/manager/vine_runtime_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
*
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

0 comments on commit 06e6b38

Please sign in to comment.