Created
July 28, 2016 08:34
-
-
Save peterjuras/88c8570ee27e7244bdf74b0508d67e1e to your computer and use it in GitHub Desktop.
Functions cold start test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(context, req) { | |
context.log('Node.js HTTP trigger function processed a request. RequestUri=%s', req.originalUrl); | |
context.res = { | |
// status: 200, /* Defaults to 200 */ | |
body: true | |
}; | |
context.done(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (context) { | |
context.done(); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request-promise'); | |
var execute5 = 'https://<my function app for 5 minutes>/api/HttpTriggerNodeJS1'; | |
var execute10 = 'https://<my function app for 10 minutes>/api/HttpTriggerNodeJS1'; | |
var execute15 = 'https://<my function app for 15 minutes>/api/HttpTriggerNodeJS1'; | |
var execute30 = 'https://<my function app for 30 minutes>/api/HttpTriggerNodeJS1'; | |
var debugMode = false; | |
function getUrls() { | |
var currentMinutes = (new Date()).getMinutes(); | |
var urls = []; | |
if (currentMinutes % 5 === 0 || debugMode) { | |
urls.push(execute5); | |
} | |
if (currentMinutes % 10 === 0 || debugMode) { | |
urls.push(execute10); | |
} | |
if (currentMinutes % 15 === 0 || debugMode) { | |
urls.push(execute15); | |
} | |
if (currentMinutes % 30 === 0 || debugMode) { | |
urls.push(execute30); | |
} | |
return urls; | |
} | |
function makeRequest(obj) { | |
var context = obj.context; | |
var url = obj.url; | |
context.log('Creating request for ' + url); | |
var startTime = (new Date()).getTime(); | |
return request(url).then(function() { | |
var endTime = (new Date()).getTime() - startTime; | |
context.log(url + ' needed ' + endTime + 'ms to complete the request'); | |
}); | |
} | |
module.exports = function (context) { | |
// | |
var requests = getUrls().map(function(url) { | |
return makeRequest({ | |
url: url, | |
context: context, | |
}); | |
}); | |
if (requests.length === 0) { | |
context.done(); | |
return; | |
} | |
Promise.all(requests) | |
.then(function() { context.done() }) | |
.catch(function(error) { | |
context.log('Error! ' + error); | |
context.done(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment