How to create a Web Job in Azure



  • Hi, the purpose of this blog post is to show developers how to create a Web Job.
    -Go to Azure Portal. 
    -Search for Resource group. Create a Resource group if you don’t have any:

     
     
    -Search for APP service and create an app service 
    -Give any name you want to the instance:
     
      
     
    -Select the publish code, or if you need any docker, select Runtime stack (either core or asp.net frame work or tomcat). Go to Monitoring tab if you want to enable Application insights. By default, it will be enabled.
     
    -Click on Review + Create and click on Create.
    -Go to Azure portal -> Resource groups -> Resource (which you have created) -> WebJob App Service. Click on “Get Publish profile” and download and import it into Visual studio to publish the web job.
    -Go to Azure portal and search for Storage accounts and click on it. 
    -Click on Add. 
    -Click on Review +Create.
     
    -Go to Storage account, click on the Storage account previously created. Click on Access keys and copy the connection string.
     
      
     
    Now go to Visual Studio to create a Console APP
     
    File->New->Project
     
      
     
    Right click on solution -> click add -> New Item -> select JSON type and name it Settings.job
     
      
     
    Open the “Settings.job” and add the following CRON expression:
     
    {
    "schedule": "0 0 */4 * * *"
    }
     
    Note: The basic format of the CRON expressions in Azure is:
     
    {second} {minute} {hour} {day} {month} {day of the week}

    Here more documentation about this:
    https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=in-process&pivots=programming-language-csharp#ncrontab-expressions 
     
    Go to App.config and add the below line in the connectionstring tag
     
    <add name="AzureWebJobsDashboard" connectionString= ”<connection string copied from storageaccount> " />
    <add name="AzureWebJobsStorage" connectionString = ”<connection string copied from storageaccount>" />  
     
    Click on "Microsoft Azure App service" or Import the profile which we downloaded in the earlier steps.   
     
    Below, the screen should appear. Go to the settings tab, set configuration to “Release,” and publish.
     
    Wait for the message below to appear in the output window of Visual Studio to assure that the deployment was successful.
     
    Go to the Azure Portal on the below screen and click on WebJob. You should be able to find your WebJob here.
     
    Original Source:
    https://www.c-sharpcorner.com/blogs/how-to-create-a-webjob-in-azure-using-visual-studio

    Official Documentation:
    https://docs.microsoft.com/en-us/azure/app-service/webjobs-dotnet-deploy-vs

    Enjoy it!



  • Comments



Add a Comment