This is an automated email from the ASF dual-hosted git repository.
dgrove pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/incubator-openwhisk-composer.git
The following commit(s) were added to refs/heads/master by this push:
new 2df3e69 Add debug setting to control needle options (#25)
2df3e69 is described below
commit 2df3e69c40ce33077e19a71660caea54d0c46cfd
Author: Olivier Tardieu <[email protected]>
AuthorDate: Tue Feb 12 16:10:53 2019 -0500
Add debug setting to control needle options (#25)
---
bin/compose.js | 4 +++-
conductor.js | 15 +++++++++++++--
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/bin/compose.js b/bin/compose.js
index e9b95ef..e426d13 100755
--- a/bin/compose.js
+++ b/bin/compose.js
@@ -24,6 +24,7 @@ const Module = require('module')
const path = require('path')
const argv = minimist(process.argv.slice(2), {
+ string: ['debug'],
boolean: ['version', 'ast', 'js'],
alias: { version: 'v' }
})
@@ -54,6 +55,7 @@ if (argv._.length !== 1 || path.extname(argv._[0]) !== '.js')
{
console.error(' --ast only output the ast for the
composition')
console.error(' --js output the conductor action code for
the composition')
console.error(' -v, --version output the composer version')
+ console.error(' --debug LIST comma-separated list of debug flags
(when using --js flag)')
process.exit(1)
}
@@ -67,7 +69,7 @@ try {
process.exit(422 - 256) // Unprocessable Entity
}
if (argv.js) {
- console.log(conductor.generate(composition).action.exec.code)
+ console.log(conductor.generate(composition, argv.debug).action.exec.code)
} else {
if (argv.ast) composition = composition.ast
console.log(JSON.stringify(composition, null, 4))
diff --git a/conductor.js b/conductor.js
index be3fb45..90e9e18 100644
--- a/conductor.js
+++ b/conductor.js
@@ -76,6 +76,17 @@ function main (composition) {
const isObject = obj => typeof obj === 'object' && obj !== null &&
!Array.isArray(obj)
+ const needleOptions = (/needle<([^>]*)>/.exec(process.env.DEBUG || '') ||
[])[1]
+
+ function invoke (req) {
+ try {
+ if (needleOptions) req = Object.assign({}, req,
JSON.parse(needleOptions))
+ } catch (err) {
+ console.err(`Ignoring invalid needle options: ${needleOptions}`)
+ }
+ return wsk.actions.invoke(req)
+ }
+
function fork ({ p, node, index }, array, it) {
const saved = p.params // save params
p.s.state = index + node.return // return state
@@ -99,7 +110,7 @@ function main (composition) {
params.$composer.redis = p.s.redis
params.$composer.openwhisk = p.s.openwhisk
params.$composer.join = { barrierId, position, count: array.length }
- return wsk.actions.invoke({ name: process.env.__OW_ACTION_NAME, params
}) // invoke branch
+ return invoke({ name: process.env.__OW_ACTION_NAME, params }) //
invoke branch
.then(({ activationId }) => { console.log(`barrierId: ${barrierId},
spawned position: ${position} with activationId: ${activationId}`) })
}))).then(() => collect(p, barrierId), error => {
console.error(error.body || error)
@@ -253,7 +264,7 @@ function main (composition) {
p.params.$composer = { state: p.s.state, stack: [{ marker: true
}].concat(p.s.stack), redis: p.s.redis, openwhisk: p.s.openwhisk }
p.s.state = index + node.return
if (!wsk) wsk = openwhisk(p.s.openwhisk)
- return wsk.actions.invoke({ name: process.env.__OW_ACTION_NAME, params:
p.params })
+ return invoke({ name: process.env.__OW_ACTION_NAME, params: p.params })
.then(response => ({ method: 'async', activationId:
response.activationId, sessionId: p.s.session }), error => {
console.error(error) // invoke failed
return { error: `Async combinator failed to invoke composition at
AST node root${node.parent} (see log for details)` }