How to make an nodejs code to run only on a single edge message processor (Cloud)

Hello all,

I wrote an node js code where I am calling another apigee proxy periodically eg. in every 2 hour. As soon as I deployed it , I came to know that its running twice.

how can I make that code to run once.

//import http module
var http = require('http');
//import node-cron module
var cron = require('node-cron');
//import request module
var request = require('request');


//cron expression and its function
cron.schedule('* */2 * * *', function(){
  request("URL of the Apigee proxy that needs to be called every two", function (error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body);
     }
    });


}); 


//nodejs app code
console.log('node.js application starting...');


var svr = http.createServer(function(req, resp) {
    resp.end('This is Scheduling APP');
});


svr.listen(9000, function() {
    console.log('Node HTTP server is listening');
});
0 1 209
1 REPLY 1

Hi @Divakar Sharma,

tl;dr this is not possible

The nodejs process is an extension of the API proxy. It automatically scales to all the available runtime components. In the trial org you get 2 MPs and the proxy and the node code will run on both the instances and will scale automatically as more are added.

If the process goes down, it will automatically be restarted as well. Incoming calls are automatically load balanced across available instances.

This is how we ensure High Availability and scalability. The platform is meant to be stateless and the APIs shouldn't need to worry which runtime server the call goes through.

You can hack around this, but it is not reliable as servers might go down, and new servers might spawn up and you will have no control of this on our Apigee SaaS.

A more pertinent question is what is it that you are trying to achieve? I can either guide you to build that functionality or help understand whether the platform is meant for such requirements.