Skip to content

Commit e5aeea5

Browse files
committed
configs for the multiple user session
1 parent 52ebe65 commit e5aeea5

File tree

6 files changed

+39
-23
lines changed

6 files changed

+39
-23
lines changed

R/application/hook.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
#' @details the application module will be add to the ``context$workflow`` tuple list.
66
#'
77
const hook = function(app) {
8-
const context = .get_context();
8+
const ssid = NULL;
9+
const context = .get_context(ssid);
910
const pool = context$workflow;
1011
const symbolMap = context$symbols;
1112
const verbose = as.logical(getOption("verbose"));
@@ -44,7 +45,7 @@ const hook = function(app) {
4445
context$symbols = symbolMap;
4546

4647
# update the global context symbol
47-
set(globalenv(), __global_ctx, context);
48+
set(globalenv(), paste([ __global_ctx,ssid],sep="-"), context);
4849

4950
invisible(NULL);
5051
}

R/context/context.R

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#'
33
#' @param outputdir the directory path to the workflow analysis workspace,
44
#' default path value is current directory.
5+
#' @param ssid the session id for multiple user environment, default NULL means global user environment
56
#'
67
#' @return this function has no return value. and the constructed
78
#' analysis environment context object will be saved in the
@@ -24,7 +25,7 @@
2425
#' ``app`` function.
2526
#' 6. pipeline: a character vector for run the application workflow.
2627
#'
27-
const init_context = function(outputdir = "./") {
28+
const init_context = function(outputdir = "./", ssid = NULL) {
2829
const analysis_output = normalizePath(`${outputdir}/analysis/`);
2930
const temp_dir = normalizePath(`${outputdir}/tmp/`);
3031
const context = list(
@@ -38,18 +39,19 @@ const init_context = function(outputdir = "./") {
3839
);
3940

4041
sink(file = `${temp_dir}/run_analysis-${get_timestamp()}.log`);
41-
set(globalenv(), __global_ctx, context);
42+
set(globalenv(), paste([__global_ctx,ssid], sep = "-"), context);
4243

4344
invisible(NULL);
4445
}
4546

4647
#' create an in-memory context object just used for run debug
4748
#'
49+
#' @param ssid the session id for multiple user environment, default NULL means global user environment
4850
#' @param mounts should be a callable function for mounts the
4951
#' application modules into the workflow registry.
5052
#'
51-
const create_memory_context = function(mounts = NULL) {
52-
set(globalenv(), __global_ctx, list(
53+
const create_memory_context = function(mounts = NULL,ssid = NULL) {
54+
set(globalenv(), paste( [__global_ctx,ssid], sep ="-"), list(
5355
root = NULL, # set all workspace to empty
5456
analysis = NULL,
5557
temp_dir = NULL,
@@ -68,11 +70,13 @@ const __global_ctx = "&[workflow_render]";
6870

6971
#' get current workflow environment context
7072
#'
73+
#' @param ssid the session id for multiple user environment, default NULL means global user environment
74+
#'
7175
#' @return the context object which is generated via the
7276
#' ``init_context`` function.
7377
#'
74-
const .get_context = function() {
75-
const workflow_render as string = __global_ctx;
78+
const .get_context = function(ssid = NULL) {
79+
const workflow_render as string = paste([__global_ctx, ssid], sep = "-");
7680

7781
if (exists(workflow_render, globalenv())) {
7882
get(workflow_render, globalenv());

R/context/workspace.R

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
#'
44
#' @param app the app list object or just the app name its
55
#' character text value.
6-
#'
6+
#' @param ssid the session id for multiple user environment, default NULL means global user environment
7+
#'
78
#' @return a character vector of the workspace directory path
89
#' of the specific analysis application.
910
#'
1011
#' @details the verbose option could be config from the
1112
#' commandline option: ``--verbose``
1213
#'
13-
const workspace = function(app) {
14+
const workspace = function(app, ssid = NULL) {
1415
const verbose = as.logical(getOption("verbose"));
15-
const context = .get_context();
16+
const context = .get_context(ssid);
1617
const temp_root = context$temp_dir;
1718
const app_name = get_app_name(app);
1819
const workdir = normalizePath(`${temp_root}/workflow_tmp/${app_name}/`);
@@ -42,42 +43,47 @@ const workspace = function(app) {
4243
#' 1. app tuple list object, which is created via the ``app`` function.
4344
#' 2. the app name character vector
4445
#' 3. the workfile path expression, should be in format like: ``app://relpath/to/file.ext``
46+
#' @param ssid the session id for multiple user environment, default NULL means global user environment
47+
#'
48+
#' @return the data file path of the required reference file inside this workflow
4549
#'
4650
#' @details the workfile path expression is in format string of: ``app://filepath``,
4751
#' example as ``getMzSet://mzset.txt``, where we could parse the reference information
4852
#' from this character string: app name is ``getMzSet``, and the relpath data is
4953
#' ``mzset.txt``. so, such configuation could be equals to the function invoke
5054
#' of the workfile function: ``workfile("getMzSet", "/mzset.txt");``.
5155
#'
52-
const workfile = function(app, relpath = NULL) {
56+
const workfile = function(app, relpath = NULL, ssid = NULL) {
5357
if (is.empty(relpath)) {
5458
if (is.character(app)) {
5559
relpath <- __workfile_uri_parser(app);
5660

5761
# gets the internal workfile reference
5862
# its physical file path
59-
file.path(WorkflowRender::workspace(relpath$app), relpath$file);
63+
file.path(WorkflowRender::workspace(relpath$app, ssid), relpath$file);
6064
} else {
6165
throw_err("the given expression value should be an internal workfile path reference!");
6266
}
6367
} else {
64-
file.path(WorkflowRender::workspace(app), relpath);
68+
file.path(WorkflowRender::workspace(app, ssid), relpath);
6569
}
6670
}
6771

6872
#' Get workspace root directory
6973
#'
74+
#' @param ssid the session id for multiple user environment, default NULL means global user environment
7075
#' @details actually this function will returns the ``output`` dir
7176
#' path which is set via the ``init_context`` function
7277
#'
73-
const workdir_root = function() {
74-
.get_context()$root;
78+
const workdir_root = function(ssid = NULL) {
79+
.get_context(ssid)$root;
7580
}
7681

7782
#' get directory folder path for the analysis output result
7883
#'
84+
#' @param ssid the session id for multiple user environment, default NULL means global user environment
7985
#' @details a character vector of the analysis result output directory.
8086
#'
81-
const result_dir = function() {
82-
.get_context()$analysis;
87+
const result_dir = function(ssid = NULL) {
88+
.get_context(ssid)$analysis;
8389
}

R/definePipeline.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#'
55
const definePipeline = function(seq) {
66
const ctx = .get_context();
7+
const ssid = NULL;
8+
79
ctx$pipeline = seq;
810
# update the global context symbol
9-
set(globalenv(), __global_ctx, ctx);
11+
set(globalenv(), paste([__global_ctx,ssid],sep ="-"), ctx);
1012

1113
invisible(NULL);
1214
}

R/finalize.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
#' Mark end of the analysis workflow
22
#'
3+
#' @details this function used for unload a specific workflow environment
4+
#'
5+
#' @param ssid the session id for the multiple user environment,default NULL means global session environment
36
#' @details release the resources of the pipeline workflow modules
47
#'
5-
const finalize = function() {
8+
const finalize = function(ssid=NULL) {
69
# saveRDS(.get_context(), file = `${.get_context()$root}/.workflow.rds`);
710

811
print("workflow finalize, ");
912
print(`*** Elapsed time '${time_span(now() - .get_context()$t0)}' ***`);
1013

1114
# unload the workflow context environment
12-
rm(list = __global_ctx);
15+
rm(list = paste([__global_ctx,ssid], sep="-"));
1316

1417
sink();
1518
}

R/utils/utils.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#' @param msg a character vector of the warning message that this
55
#' workflow produced.
66
#'
7-
const echo_warning = function(msg, app = NULL) {
8-
const warning_log = `${.get_context()$temp_dir}/warning`;
7+
const echo_warning = function(msg, app = NULL, ssid = NULL) {
8+
const warning_log = `${.get_context(ssid)$temp_dir}/warning`;
99
const link = file(warning_log, "append");
1010
const app_name = get_app_name(app);
1111

0 commit comments

Comments
 (0)