helloworld.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* a simple hello world plugin... it listens for "POST /hello" requests... requests are received by "csworker" and forwarded to "asworker"... both respond with their __worker\'s id and with a counter of the number of handled requests */
  2. {
  3. 'interfaces' : [{'method':'POST', 'url=':'/hello'}],
  4. 'localcontext' : {'counter':0},
  5. 'csworker' :
  6. function(resp,method,uri,reqData,wcontext)
  7. {
  8. var self = this;
  9. _do.chain(
  10. [__wHttpReq(method, uri+'?wid='+wcontext.__aswid, reqData)])(
  11. function()
  12. {
  13. self.localcontext.counter++;
  14. __postMessage(
  15. {'statusCode':200,
  16. 'changelog':
  17. [{'op':'SYSOUT',
  18. 'text':'Hello #'+self.localcontext.counter+' from csworker #'+__wid}],
  19. 'sequence#':__sequenceNumber(),
  20. 'respIndex':resp});
  21. },
  22. function(err) {__postInternalErrorMsg(resp,err);}
  23. );
  24. },
  25. 'asworker' :
  26. function(resp,method,uri,reqData,wcontext)
  27. {
  28. this.localcontext.counter++;
  29. __postMessage(
  30. {'statusCode':200,
  31. 'changelog':
  32. [{'op':'SYSOUT',
  33. 'text':'Hello #'+this.localcontext.counter+' from asworker #'+__wid}],
  34. 'sequence#':__sequenceNumber(),
  35. 'respIndex':resp});
  36. }
  37. }