I have website on azure app service running in 5 different deployment slots(Dev, UAT, Staging, Prelive-1, Prelive-2), each of which containing a timer triggered azure webjob written in .NET Core 2.2(properly placed at the right place in App_Data). Each Webjob contains an appsettings.json file which has different URLs to hit.
The webjob runs in every 5 mins and hits the url from the appsettings, but when I check logs in azure insights(configured properly) I see only one of the deployment slot is running(90% of the times its the first deployment slot -- "DEV" one). I want to make all the webjob run in all the deployment slots.
They all have same storage and app insights configured.
One more problem Let say if I restart any deployment slot e.g. Prelive-1 then instantly the webjobs execute and after 5 mins its doesn't. I can only see the processing being done in DEV but not in others
Is there anyway to make them run all at once or one by one whatever but I just want to make all the deployments slots to run the webjob in every 5 mins.
Below is my Program.cs
public class Program
{
public static async Task Main()
{
HostBuilder hostBuilder = new HostBuilder();
hostBuilder.ConfigureWebJobs(builder =>
{
builder.AddAzureStorageCoreServices();
builder.AddAzureStorage();
builder.AddTimers();
})
.ConfigureAppConfiguration((hostContext, configurationBuilder) =>
{
configurationBuilder.AddJsonFile($"appsettings.json", optional: false, reloadOnChange: false);
})
.ConfigureLogging((context, loggingBuilder) =>
{
string instrumentationKey = context.Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"];
if (!string.IsNullOrEmpty(instrumentationKey))
loggingBuilder.AddApplicationInsightsWebJobs(logBuilder => logBuilder.InstrumentationKey = instrumentationKey);
})
.ConfigureServices(services =>
{
services.AddHttpClient();
})
.UseConsoleLifetime();
using (var host = hostBuilder.Build())
{
await host.RunAsync();
}
}
Below is my Function.cs
public class Function1
{
const string CheckPendingFulfillmentsUrlConfigKey = "CheckPendingFulfillmentsUrl";
const string WebJobTimerExpression = "0 */5 * * * *";
readonly IHttpClientFactory httpClientFactory;
readonly ILogger<Function1> logger;
readonly string CheckPendingFulfillmentsUrl;
public Function1(IHttpClientFactory HttpClientFactory, ILogger<Function1> Logger, IConfiguration config)
{
httpClientFactory = HttpClientFactory;
logger = Logger;
CheckPendingFulfillmentsUrl = config[CheckPendingFulfillmentsUrlConfigKey];
}
public async Task TriggerCheckPendingFulfillments([TimerTrigger(WebJobTimerExpression, RunOnStartup = false)] TimerInfo timerInfo, CancellationToken cancellationToken)
{
using (var httpClient = httpClientFactory.CreateClient())
{
if (!string.IsNullOrEmpty(CheckPendingFulfillmentsUrl))
{
await httpClient.GetAsync(CheckPendingFulfillmentsUrl);
logger.LogInformation(string.Format(Properties.Resources.Info_CheckPendingFulfillmentsTriggered, CheckPendingFulfillmentsUrl));
}
}
}
}