Achraf Ben Alaya
No Result
View All Result
  • News
  • Blog
    • blazor
    • c#
    • Cloud
      • Azure
    • docker
    • sql
    • xamarin
    • Dapr
    • Tricks, Tips and Fixes
  • Cloud
  • Motivation
  • General Tips & Fix
  • Exam Preparation
    • AZ-104
    • AZ-400
  • About
    • Resume
SUBSCRIBE
  • News
  • Blog
    • blazor
    • c#
    • Cloud
      • Azure
    • docker
    • sql
    • xamarin
    • Dapr
    • Tricks, Tips and Fixes
  • Cloud
  • Motivation
  • General Tips & Fix
  • Exam Preparation
    • AZ-104
    • AZ-400
  • About
    • Resume
No Result
View All Result
Achraf Ben Alaya
No Result
View All Result
ADVERTISEMENT
Home

Run background tasks with WebJobs in Azure App Service

achraf by achraf
August 21, 2021
in Azure, Blog, Cloud
3 min read
0
Run background tasks with WebJobs in Azure App Service
0
SHARES
1.1k
VIEWS
Share on FacebookShare on Twitter

Introduction

WebJobs is a feature of Azure App Service that enables you to run a program or script in the same instance as a web app, API app, or mobile app. There is no additional cost to use WebJobs.

You can use the Azure WebJobs SDK with WebJobs to simplify many programming tasks. WebJobs is not yet supported for App Service on Linux.
Azure Functions provides another way to run programs and scripts

What a web job can do  :

  • Image processing ( CPU-intensive work) .
  • Queue/blobs/notification processing
  • Example: when a new image is uploaded the original will be saved to blob storage and a thumbnail will be generated and used (with saving the link of the thumbnail and original image link to SQL)

As Web Job we can run applications or script written in many popular languages/technologies:

  • .cmd, .bat, .exe
  • .ps1
  • .sh
  • .php
  • .py
  • .js (using Node.js)
  • .jar

Job modes

Each Web job can be configured to run in one of the following modes:

1. Continuous – runs all the time, analogy to Windows Service configured with auto start option is in place. Hosting environment monitors the job status and brings it up when process is down. (NOTE: With the current preview, this works properly on standard web sites with ‘always on’ setting. Caution is required when we scale the site up from Standard mode – Web Jobs will be terminated when there is no request for 20 minutes)

2. Scheduled – runs at particular times.

3. On Demand – runs when started manually…

Demo :

We are going to create a basic sample app that will insert a row to an SQL table and will be scheduled to run every minute.

For that, we are going to need first to create our project using the visual studio :

using Microsoft.Extensions.Logging;
using System;
using System.Data.SqlClient;

namespace test
{
    class Program
    {
        private ILogger log;
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            string connString = "";
            Console.WriteLine($"C# Timer trigger function executed at: {DateTime.Now}");

            SqlConnection conn = new SqlConnection(connString);

            try
            {
                Console.WriteLine("Openning Connection ...");

                //open connection
                conn.Open();
                string insert = "INSERT INTO checkcontainers (name ,timing) VALUES (@name,@time)";
                string name = "demo at";
                string time = System.DateTime.Now.ToString();
                using (SqlConnection connection = new SqlConnection(connString))
                {

                    connection.Open();
                    using (SqlCommand command = new SqlCommand(insert, connection))
                    {
                        command.Parameters.AddWithValue("@name", name);
                        command.Parameters.AddWithValue("@time", time);
                        command.ExecuteNonQuery();
                        command.Dispose();

                    }
                    conn.Close();
                }

                Console.WriteLine($"C# Timer trigger function end executed at: {DateTime.Now}");

                Console.WriteLine("Connection successful!");
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message);
            }

           
            Console.WriteLine("All Records inserted Successfully");

            // Console.Read();

            // wait 2 seconds before closing Console Application
            System.Threading.Thread.Sleep(2000);


        }
    }
}

Now we have our project ready, there is many ways to publish it, and I’m going to use a classic way which is to publish it to a folder and I’m going to zip that folder.

Now after we have our zip file, we need to have  app service and web app running and there we look for web jobs :

and now we upload the zip file and we configure it to run “Triggered”  :

And like that, we have our service up and running and doing its job.

ShareTweet
Previous Post

Dapr – State management (redis) Part 1/2

Next Post

Configure postman / newman API tests in Azure DevOps

Related Posts

Switch to Azure Container Registry from Docker Hub
Azure

From Docker Hub, switch to Azure Container Registry & AKS

January 16, 2023
132
How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)
Azure

How to configure an ingress controller using TLS/SSL for the Azure Kubernetes Service (AKS)

November 25, 2022
229
How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)
Azure

How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)

November 23, 2022
102
How to setup nginx reverse proxy for aspnet core apps with and without  Docker compose
Azure

How to setup nginx reverse proxy for aspnet core apps with and without Docker compose

November 23, 2022
153
Win free certifications at the Microsoft Build Cloud Skills Challenge | May 2022 🎁
Blog

Win free certifications at the Microsoft Build Cloud Skills Challenge | May 2022 🎁

May 28, 2022
107
Generating report for SSL Certificates for Websites with PowerShell
Azure

Generating report for SSL Certificates for Websites with PowerShell

April 10, 2022
386
Next Post
Configure postman / newman API tests in Azure DevOps

Configure postman / newman API tests in Azure DevOps

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Terraform

Certifications

Microsoft certified trainer (MCT)

Recommended

How To host an Angular app on Azure

September 29, 2020
1k
Setting up Serilog in ASP.NET Core

Setting up Serilog in ASP.NET Core

September 15, 2020
1.7k
How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)

How to configure an ingress controller using TLS/SSL for the Azure Kubernetes Service (AKS)

November 25, 2022
229
Installing WordPress with docker image of XAMPP

Installing WordPress with docker image of XAMPP

April 21, 2020
665
Run background tasks with WebJobs in Azure App Service

Run background tasks with WebJobs in Azure App Service

August 21, 2021
1.1k
How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)

How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)

November 23, 2022
102
Facebook Twitter LinkedIn Youtube
Switch to Azure Container Registry from Docker Hub

From Docker Hub, switch to Azure Container Registry & AKS

January 16, 2023
How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)

How to configure an ingress controller using TLS/SSL for the Azure Kubernetes Service (AKS)

November 25, 2022
How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)

How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service (AKS)

November 23, 2022

Categories

  • Apps (1)
  • Azure (39)
  • blazor (2)
  • Blog (62)
  • c# (7)
  • Cloud (37)
  • Dapr (4)
  • docker (3)
  • Games (1)
  • General Tips & Fix (1)
  • Motivation (3)
  • motivation (2)
  • News (9)
  • Resume (1)
  • sql (4)
  • Tricks, Tips and Fixes (3)
  • xamarin (5)
No Result
View All Result
  • News
  • Blog
    • blazor
    • c#
    • Cloud
      • Azure
    • docker
    • sql
    • xamarin
    • Dapr
    • Tricks, Tips and Fixes
  • Cloud
  • Motivation
  • General Tips & Fix
  • Exam Preparation
    • AZ-104
    • AZ-400
  • About
    • Resume