Add an App Setting in each slot called "IsStaging" with true and false values then when app service warms up (Startup or method consuming messages) stop requests so messages are not consumed from the Staging slot.
if (CurrentConfiguration.IsStaging)
{
logger.LogWarn("Staging slot cannot consume messages");
return;
}
UPDATE for WebJob:
static void Main(string[] args)
{
JobHost host = CreateJobHost();
if (CurrentConfiguration.IsStaging)
{
host.Call(typeof(Program).GetMethod("DoStagingInfiniteLoop"));
}
else
{
host.Call(typeof(Program).GetMethod("ProcessQueue"));
}
}
private static JobHost CreateJobHost()
{
JobHostConfiguration jobHostConfig = new JobHostConfiguration();
jobHostConfig.DashboardConnectionString = "DashboardCS";
jobHostConfig.StorageConnectionString = "StorageCS";
var JobHost = new JobHost(jobHostConfig);
return JobHost;
}
[NoAutomaticTrigger]
public static void DoStagingInfiniteLoop(TextWriter logger, CancellationToken token)
{
const int LOOP_TRACE_INTERVAL = 10000;
ProcessLogger.WriteTrace("This is a staging environment, waiting...");
while (true)
{
Task.Delay(LOOP_TRACE_INTERVAL).Wait(token);
}
}
[NoAutomaticTrigger]
public static void ProcessQueue(TextWriter logger, CancellationToken token)
{
//Your processing code here
}