简体   繁体   English

OpenWhisk /节点-承诺无法解决

[英]OpenWhisk/Node — Promise Is Not Resolving

I've tested a reddit bot locally for a while now, and gotten it working locally. 我已经在本地测试了reddit bot一段时间,并使其在本地运行。 So now I'm trying to invoke it on OpenWhisk. 所以现在我想在OpenWhisk上调用它。 The line where my troubles seem to come up is: 我的麻烦似乎出现的那条线是:

r.getInbox( {"filter":"mentions", "append":false } ).then( newMentions, console.err );

newMentions is never triggered. newMentions永远不会触发。 I've made the first line in it a console.log, and I've replaced newMentions with console.log. 我已经将第一行作为console.log,并用console.log替换了newMentions。

console.logs before and after this line get called just fine, and getInbox works fine on my local machine and should work just fine here. 在此行之前和之后的console.logs都可以正常调用,并且getInbox在我的本地计算机上可以正常运行,并且在这里应该可以正常运行。 I'm not getting any error anywhere, even from console.err in the above line. 即使在上一行的console.err中,我也没有任何错误。

So my current guess is that my OpenWhisk instance somehow ends before getInbox can resolve. 因此,我目前的猜测是,我的OpenWhisk实例某种程度上在getInbox可以解析之前就结束了。 Is that right? 那正确吗? I have it set to 60s/512mb, and it's not taking anywhere near 60s, and I can't imagine it takes up 512mb. 我将其设置为60s / 512mb,并且它不会占用60s的任何时间,而且我无法想象它占用了512mb。 So... Do I need to manually force OpenWhisk to wait for the promise to resolve? 所以...我是否需要手动强制OpenWhisk等待承诺解决? How would I do that? 我该怎么办? Or is there some other error I'm not seeing? 还是我没有看到其他错误?

To be clear: I'm using snoowrap for reddit. 需要明确的是:我正在使用snoowrap进行reddit。 r is a proper snoowrap object, and getInbox is a snoowrap function that I'm pretty sure I'm using correctly, which returns a promise for json data representing an inbox. r是一个合适的snoowrap对象,而getInbox是一个snoowrap函数,我敢肯定我使用的是正确的函数,该函数返回表示收件箱的json数据的承诺。 And again, even if it were empty, newMentions should still be called, right? 再说一次,即使它是空的,仍然应该调用newMentions,对吗?

return the promise to the main function 将promise返回给主函数

function main(){
  return r.getInbox( {"filter":"mentions", "append":false } ).then( newMentions, console.error );
}

this way OpenWhisk will wait on the Promise 这样,OpenWhisk将在Promise上等待

make sure your resolve function newMentions or reject function returns a JSON object, it will be the result of the Action 确保您的resolve函数newMentions或reject函数返回JSON对象,这将是Action的结果

Also console.err is not a function is console.error 另外console.err不是一个功能是console.error

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM