Git Product home page Git Product logo

app-service-linux-webjobs's Introduction

Azure App Service Linux + WebJobs

This repo is a simple demonstration on how to run worker services / webjobs on Azure App service for Linux.

There's an youtube video where I explain in detatils, portuguese only https://www.youtube.com/watch?v=557kiOUffdw

How to run

Build the WorkerServiceWithHttp image and push to your own Container Registry and create a new app service with that container

How it works

The app service cluster will send a health check request on the configured http port (defaults to 80) if it returns a 200 status that means the container is healthy if other status it will try to restart the container. So all you need to do is start a simple kestrel service listen for those requests.

    public class HttpWorker : BackgroundService
    {
        private IHost _webHost;

        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            /*
             * In order to run on AppService for Containers we need to have a http port exposed
             * so the cluster can verify if the container is running
             */
            _webHost = Host.CreateDefaultBuilder()
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.Configure(c =>
                        c.Run(async s => await s.Response.WriteAsync("Hello App Service Containers", stoppingToken))
                    );
                })
                .Build();

            return _webHost.StartAsync(stoppingToken);
        }

        public override Task StopAsync(CancellationToken cancellationToken)
        {
            _webHost?.StopAsync(cancellationToken);
            return base.StopAsync(cancellationToken);
        }
    }

app-service-linux-webjobs's People

Contributors

rsantosdev avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.