Skip to content

Commit fad6f42

Browse files
committed
Add support for local workflow configuration files
1 parent 612c2ae commit fad6f42

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

bin/hflow

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var spawn = require('child_process').spawn,
3131
dbId = 0,
3232
plugins = [],
3333
recoveryMode = false, recoveryData = { 'input': [], 'outputs': {}, 'settings': {} },
34+
glob = require('glob'),
3435
wfDirFull; // logged in the persistence journal
3536

3637
var hfroot = pathtool.join(require('path').dirname(require.main.filename), "..");
@@ -132,6 +133,35 @@ function hflow_run() {
132133

133134
wfDirFull = pathtool.resolve(wfpath);
134135

136+
// Read workflow configuration files if exist
137+
// all files matching pattern `workflow.config[.name].json` will be matched
138+
// all config will be passed to workflow functions via `context.appConfig[.name]`
139+
var wfConfig = {};
140+
// 1. Look for main config file -- workflow.config.json
141+
var wfConfigFilePath = pathtool.join(wfDirFull, "workflow.config.json");
142+
if (fs.existsSync(wfConfigFilePath)) {
143+
try {
144+
let rawdata = fs.readFileSync(wfConfigFilePath);
145+
wfConfig = JSON.parse(rawdata);
146+
} catch(e) {
147+
console.log("Error reading/parsing workflow config file:", e);
148+
}
149+
}
150+
// 2. Look for secondary config files -- workflow.config.{name}.json
151+
var configFiles = glob.sync("workflow.config.*.json");
152+
configFiles.forEach(function(file) {
153+
try {
154+
let rawdata = fs.readFileSync(file);
155+
let secondaryConfig = JSON.parse(rawdata);
156+
let match = file.match(/workflow\.config\.(.*).json/);
157+
let name = match[1];
158+
wfConfig[name] = secondaryConfig;
159+
} catch (e) {
160+
console.log("Error reading/parsing workflow config file ", file, e);
161+
}
162+
});
163+
console.log(wfConfig);
164+
135165
var runWf = function(wfId, wfName) {
136166

137167
/*function makeId() {
@@ -144,7 +174,9 @@ function hflow_run() {
144174
return id.join("");
145175
}*/
146176

147-
var config = {"emulate":"false", "workdir": wfDirFull};
177+
var config = wfConfig;
178+
config["emulate"] = "false";
179+
config["workdir"] = wfDirFull;
148180

149181
if (recoveryMode) {
150182
config.recoveryData = recoveryData;

wflib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,7 @@ function public_invokeProcFunction(wfId, procId, firingId, insIds_, insValues, o
14061406
//onsole.log(JSON.stringify(procInfo.config)); //DEBUG
14071407
var conf = procInfo.config ? JSON.parse(procInfo.config): {};
14081408
conf.name = procInfo.name;
1409+
conf.appConfig = appConfig;
14091410
//var executor = procInfo.executor ? procInfo.executor: null;
14101411

14111412
//onsole.log("INS VALUES", insValues);

0 commit comments

Comments
 (0)