Friday, 5 July 2019

azure function


best practise -- function

js guide:

create a function with ide:
you also can directly create a function on azure portal (web)

azure function.

Trigger ,  you can use timer, or http or cosmos as a trigger, which means what will call your code(the function).

Timer, it is a corn job.

Http,  it will generate a url, if you access the url it will call your code.  -- this could be used as an api.

cosmos.  you will need to link your Function to a collection, then once insert or update done on your table, then your function will be called.  but i found it doesn't work with new created db..........

Input, Functions can have multi inputs.

cosmos,  you can link your input to a cosmos collection (you can give an collection id, you can also give a sql). once your code is called,  Azure will run your sql to give you data or give you the whole collect, or give you the collection with the given id.

e.g. below is my function with timer tigger, and i have created an Input to connect to one of my cosmos collection:

module.exports = async function (context, myTimer, input) {
var timeStamp = new Date().toISOString();
if (myTimer.IsPastDue)
context.log('JavaScript is running late!');
context.log('_------------------JavaScript timer trigger function ran!', timeStamp);

context.log( input); // here will print the collection data


No comments:

Post a comment