0
votes

I am working on a sharepoint online team site collection. and i want to define a job which runs on daily basis to do the following:-

  1. Integrate with SharePoint REST API, to get all the items inside a certain list which have their Due Date = Today.
  2. send an email to a sharepoint group.

Now when i was working on such a task inside SharePoint on-premises, i use to follow this approach :-

1- I create a .net console app which integrate with SharePoint REST API, get the related items, and finally send the email using .NET WebClient, something as follow :-

//do the checks then send an email to the related group
    using (MailMessage myMailMessage = new MailMessage())
            {
                SPOutboundMailServiceInstance smtpServer = currentsite.WebApplication.OutboundMailServiceInstance;
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(smtpServer.Server.Address);
                myMailMessage.IsBodyHtml = true;
                myMailMessage.Subject = subject;
                myMailMessage.Body = body;
                smtp.Send(myMailMessage);
                //code goes here..
            }

2- place the console application on the sharepoint server.

3- using windows task scheduler tool, i create a task which executes the console application on daily basis (@1:00 am for example).

so now in sharepoint online i am not sure how i can host my console application + how i can schedule it ?. i already converted all my code inside the console application to use the client-side module instead of server-side module. but my question is about hosting & scheduling the console application. i read about these options inside Azure mainly :-

  1. WebJobs
  2. Azure Functions

but i am not sure which appraoch is better to follow ? and which of the 2 tools mimic the appraoch of scheduling the console application using windows tasks scheduler?. now i read this article https://anthonychu.ca/post/azure-functions-scheduled-executables/ about Azure functions, but i got confused on what does function.jso file do? and not sure if i can run standard console application using these tools? also is there a UI to configure the trigger schedule as in the windows tasks scheduler case? Thanks

1
I would use a function app with a timer trigger. I would recommend creating a function app in the Azure portal and seeing how far you get. It's pretty intuitive.Jason P
@JasonP can you explain why you will chose functions instead of webjobs?john Gu
Functions are the successor to webjobs. They have expanded functionality like more triggers and pay-per-run. I don't think there's really a reason to use a webjob for a new project.Jason P

1 Answers

1
votes

As Jason said, Functions are the successor to webjobs. Azure Functions is all about taking that core purpose of the WebJobs SDK, hosting it as a service, and making it easy to get started with other languages. We also introduce the "Serverless" concept here because it made a lot of sense to do so - we know how our SDK scales, so we can do intelligent things for you. While webjobs are backend console application which deploy in Web App.

but i got confused on what does function.json file do?

The function.json file that contains the configuration metadata for the function. A function can only have a single trigger binding, and can have multiple input/output bindings. Below are examples for each of the trigger types. You could refer to this wiki.

For deploying console app to Azure WebJobs, you could refer to this article to zip your console app and upload it. To set schedule trigger, you need to add a settings.job in you console app.

{
    "schedule": "0 */15 * * * *"
}

For deploy console app to Azure Function, you could refer to the article as you have provided with a timetrigger binding.

{
  "bindings": [
    {
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "*/15 * * * * *",
      "runOnStartup": false
    }
  ]
}

So I recommend to use Azure Function to host.