Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Managing app init with multiple instance #11389


User avatar
0
Ricavir created

Hi,

I would like to configure my app according to the current instance count. The goal is to activate background jobs on the first instance of the app ; and to avoid to activate it for the next instances.

I'm using Azure App Service and starting the app with 1 instance. The app can switch to 2/3or 4 instances according to the CPU/RAM load.

I will use the environment variable WEBSITE_INSTANCE_ID to manage this : this value gives a unique instance ID.

My idea is to store this value (in cache or somewhere else). When app starts, I need to read this value in the PostInitialize method of WebHostModule class. If the value exists, I don't activate the background jobs for the instance. If no value set, then I start the backgound jobs for current instance (which should be the first).

Can you please help me to achieve this ? Specialy for the read/write data in the postinitialize method ?

This could help a lot of people that is struggling out with multiple instances on ABP.

Thks


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @Ricavir

    Are you able to get WEBSITE_INSTANCE_ID ? If so, you can directly set Configuration.BackgroundJobs.IsJobExecutionEnabled by using this value.

    Probably I couldn't understand at which point you need help. Please let me know if my answer doesn't help.

  • User Avatar
    0
    Ricavir created

    Hi @Ismcagdas,

    It has been a while since the last time :)

    In fact, WEBSITE_INSTANCE_ID is an environment variable available on Azure App Service VM's. So, yes, I can read it.

    My problem is that I want to store it somewhere outside the VM, this is why I need your help. I was thinking to store it in cache (I'm using Redis) or in Azure blob storage.

    What is your advise about this ? Can I access cache or azure storage before setting Configuration.BackgroundJobs.IsJobExecutionEnabled ?

    My goal is to activate background job execution only in the first instance ; the one that will start the app. Therefore, if a new instance is pushed in by Azure (automatic scale), the background job execution will not be started twice.

  • User Avatar
    0
    Ricavir created

    Sorry @Ismcagdas, I just saw that Hangfire is able to manage background jobs on multiple instances. I will try it and come back to you if I need some additional help. This ticket can be closed.