Example of creating a simple scheduled trigger

Consider a simple example where we have to display a "good morning" message on screen every day in the morning at 8 AM. This situation is related to time so we need to use a schedule trigger. This is the type of trigger we will look at later in this chapter. Let's start creating a function with the schedule trigger first:

  1. Log in to the Azure Portal.

 

  1. Click on the top left + icon | Compute | Function App:
  1. Once we click on Function App, the next screen will appear, where we have to provide a unique function App name, Subscription, Resource Group, Hosting Plan, Location, Storage, and then click on the Create button:
  1. Once we click on the Create button, Azure will start to deploy this function. Once this function is deployed, it will be seen in Notifications, as shown in the following screenshot:
  1. Click on Notifications and check the Functions details and add the trigger:
  1. To add a trigger in this function, click on the + icon next to Functions and then click on Custom function:
  1. Now we have to select Language and type the name of the trigger. Once we provide the name and trigger value it will provide the available template for us after filtering all the templates:
  1. Scroll down and type the trigger name and schedule. The Schedule value is a six-field CRON expression. Click on the Create button:

By providing 0 0/5 * * * *, the function will run every 5 minutes from the first run.

  1. Once we click on the Create button, we will see the template code on the screen as follows:

Here, we have to write code. Whatever action we want to perform, we have to write it here.

Now write the code and click on the Save and run button.

  1. Once we run the code, we can see the output in the logs, as shown in the following screenshot:

Note the timing.

It runs at an interval of 5 minutes.

Now we want it to run only once a day at 8 AM. To do this, we have to change the value of the schedule.

  1. To edit the value in the trigger, click on Integrate, type the value, and then click on the Save button:
  1. Now, again, click on goodMorningTriggerJS, modify the code, and test it.

So, this is all about creating a simple trigger with the Azure Function. Now, we will look at the different types of triggers available in Azure.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.3.175