我在Bluemix上的OpenWhisk上創建了兩個操作。當我可以從OpenWhisk平臺之外打電話時,兩者都獨立工作。但我想從1動作中調用動作1,和現在用的語法如下:如何在bluemix上的openwhisk平臺內調用openwhisk操作?
var openwhisk = require('openwhisk');
function main(args){
const name = 'action2';
const blocking = true;
const params = { param1: 'sthing'};
var ow = openwhisk();
ow.actions.invoke({name, blocking, params})
.then(result => {
console.log('result: ', result);
return result; // ?
}).catch(err => {
console.error('failed to invoke actions', err);
});
}
但我得到一個空的結果,並沒有控制檯消息。一些幫助會很好。
UPDATE1:
當添加的建議返回選項,返回OpenWhisk的承諾如下:
return ow.actions.invoke({name, blocking, params})
.then(result => {
console.log('result: ', result);
return result;
}).catch(err => {
console.error('failed to invoke actions', err);
throw err;
});
動作2的響應值並不如預期,但包含:
{ "isFulfilled": false, "isRejected": false }
其中我期待action2(讀取Google Sheets API)的返回消息並分析結果:
{
"duration": 139,
"name": "getEventCfps",
"subject": "[email protected]",
...
"response": {
"result": {
"message": [
{
"location": "Atlanta, GA",
"url": "https://werise.tech/",
"event": "We RISE Women in Tech Conference",
"cfp-deadline": "3/31/2017",
...
}
]
},
"success": true,
"status": "success"
},
...
}
所以我期待我不解析'.then(結果'變量在action1中正確?當我從OpenWhisk通過Postman或API Connect單獨測試action2時,或者直接通過OpenWhisk/Bluemix中的「運行此操作」,它會返回正確的值。
UPDATE2:
好的解決。我在一個在action1中調用的函數中調用了ow.actions.invoke到action2,這個返回嵌套導致了這個問題。直接在主函數中移動調用代碼時,所有解決方案都按預期方式解決。嵌套承諾和返回時遇到雙重麻煩。 Mea culpa。謝謝大家
注意'openwhisk'已經返回一個承諾,因此,創建一個新的是多餘的。你可以'返回ow.actions.invoke(...)' – markusthoemmes
我已經在編輯中解決了這個問題。 –
該文檔不是很清楚,如果它是actionName或name,或者兩者中的任何一個都可以使用。 – csantanapr