Skip to content

Commit 6f82026

Browse files
committed
Merge branch 'develop' of https://github.com/dice-cyfronet/hyperflow into develop
2 parents 38a49f8 + e0ddc26 commit 6f82026

File tree

5 files changed

+4581
-19
lines changed

5 files changed

+4581
-19
lines changed

bin/hflow

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
11
#!/usr/bin/env node
2+
3+
var redisURL = process.env.REDIS_URL ? {url: process.env.REDIS_URL} : {};
4+
5+
26
var docopt = require('docopt').docopt,
37
spawn = require('child_process').spawn,
4-
fs = require('fs'),
8+
fs = require('fs'),
59
pathtool = require('path'),
610
redis = require('redis'),
7-
rcl = redis.createClient(),
11+
rcl = redis.createClient(redisURL),
812
wflib = require('../wflib').init(rcl),
913
Engine = require('../engine2'),
1014
async = require('async'),
11-
dbId = 0;
15+
dbId = 0,
16+
plugins = [];
1217

1318
var doc = "\
1419
Usage:\n\
15-
hflow run <workflow_dir_or_file> [-s] [--with-server] \n\
16-
hflow start-server\n\
17-
hflow send <wf_id> ( <signal_file> | -d <signal_data> )\n\
20+
hflow run <workflow_dir_or_file> [-s] [--with-server] [-p <plugin_module_name> ...]\n\
21+
hflow start-server [-p <plugin_module_name> ...]\n\
22+
hflow send <wf_id> ( <signal_file> | -d <signal_data> ) [-p <plugin_module_name> ...]\n\
1823
hflow -h | --help | --version";
1924

2025
var opts = docopt(doc);
2126
var hfroot = pathtool.join(require('path').dirname(require.main.filename), "..");
2227

28+
if (opts['-p']) {
29+
opts['<plugin_module_name>'].forEach(load_plugin);
30+
}
31+
2332
if (opts.run) {
2433
hflow_run();
2534
} else if (opts.send) {
@@ -28,6 +37,17 @@ if (opts.run) {
2837
hflow_start();
2938
}
3039

40+
function load_plugin(plugin_name) {
41+
try {
42+
var Plugin = require(plugin_name);
43+
plugins.push(new Plugin());
44+
} catch (err) {
45+
console.log("Plugin module:", plugin_name, "not found!");
46+
console.log(err);
47+
process.exit(1);
48+
}
49+
}
50+
3151
function hflow_start() {
3252
var server = require('../server/hyperflow-server.js')(rcl, wflib);
3353
server.listen(process.env.PORT, function() { });
@@ -42,27 +62,30 @@ function hflow_run() {
4262
if (opts['--with-server']) {
4363
hflow_start(); // start the HTTP server
4464
}
45-
65+
4666
if (wfstats.isDirectory()) {
4767
wffile = pathtool.join(wfpath, "workflow.json");
4868
} else if (wfstats.isFile()) {
4969
wffile = wfpath;
5070
wfpath = pathtool.dirname(wfpath);
5171
}
5272

53-
var runWf = function(wfId) {
73+
var runWf = function(wfId) {
5474
var config = {"emulate":"false", "workdir": pathtool.resolve(wfpath)};
5575
var engine = new Engine(config, wflib, wfId, function(err) {
5676
// This represent custom plugin listening on event from available eventServer
5777
// engine.eventServer.on('trace.*', function(exec, args) {
5878
// console.log('Event captured: ' + exec + ' ' + args + ' job done');
5979
// });
80+
plugins.forEach(function(plugin) {
81+
plugin.init(rcl, wflib, engine);
82+
});
6083
engine.runInstance(function(err) {
6184
console.log("Wf id="+wfId);
6285
if (opts['-s']) {
6386
// Flag -s is present: send all input signals to the workflow -> start execution
6487
wflib.getWfIns(wfId, false, function(err, wfIns) {
65-
engine.wflib.getSignalInfo(wfId, wfIns, function(err, sigs) {
88+
engine.wflib.getSignalInfo(wfId, wfIns, function(err, sigs) {
6689
engine.emitSignals(sigs);
6790
});
6891
});
@@ -75,7 +98,7 @@ function hflow_run() {
7598
rcl.select(dbId, function(err, rep) {
7699
//rcl.flushdb(function(err, rep) { // flushing db here deletes the global 'hfid' entry (created earlier)
77100
wflib.createInstanceFromFile(wffile, '', function(err, id) {
78-
cb(err, id);
101+
cb(err, id);
79102
});
80103
//});
81104
});

0 commit comments

Comments
 (0)