Scenario : There is a server which hosts its data every hour through an API.
From the below link I came to know that " the nodejs code that you embed into an Apigee Edge proxy starts running as soon as you deploy your api proxy."
https://community.apigee.com/questions/27019/schedule-a-thread-in-apigee-edge.html
So I wrote a code is javascript using cron , below is the code.
//This code will hit http://mocktarget.apigee.net every 4th second.
var schedule = require('node-schedule');
var j = schedule.scheduleJob('*/4 * * * * *', function(){
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; var xhr = new XMLHttpRequest(); xhr.open('GET',"http://mocktarget.apigee.net",false); xhr.send(); console.log(xhr.responseText); console.log(xhr.status);
});
As soon as I ran this code I got this
Execution of cron failed with error: Javascript runtime error: "ReferenceError: "require" is not defined. (cron:1)"
To resolve this I imported require.js in jsc and included like this
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" name="cron">
<DisplayName>cron</DisplayName>
<Properties/>
<ResourceURL>jsc://cron</ResourceURL>
<IncludeURL>jsc://require.js</IncludeURL>
</Javascript>
Now the above error is resolve , new error is
Execution of cron failed with error: Exception thrown from JavaScript : Error: Module name "node-schedule" has not been loaded yet for context: _. Use require([]) http://requirejs.org/docs/errors.html#notloaded (cron#143)
How to import this node-schedule module now?
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |