How to differentiate code running in production and staging slots

855 Views Asked by At

I have 2 Azure Functions: Azure Function 1 and Azure Function 2.

Azure Function 1 is timer trigger function which runs every n minutes and puts a message to a queue.

Azure Function 2 is a service bus trigger function which gets triggered after receiving a message from the queue

As of now, I only have one deployment slot for these 2 functions - production slot.

I'm trying to add a new staging slot for both functions.

Both staging slot and production slot will have same app settings (uses same queue, same log workspace).

Now, let's say Azure Function 1 gets triggered and puts a message to queue. Will there be 2 messages in the queue (from Azure Function 1 in staging slot and production slot)? Will Azure Function 2 in both staging slot and production slot gets triggered after receiving the message? Please help me understand.

UPDATE:

For clarification, my understanding is that both production and staging slots are in running state all the time. So, Azure Function 1 (timer trigger function) in both staging and production slots get triggered and put a message to the same queue (since both slots use the same queue). Will there be 2 messages in the queue? If so, will Azure Function 2 in both production and staging slots get triggered (since Azure Function 2 is a service bus trigger function)? So, should different queues be used for production/staging slots?

1

There are 1 best solutions below

0
On

Yes, it looks like you will need to either use a different queue in the code for your slot. I am working with a customer who had a similar issue with their main Function and slot both triggering. There is info here recommending to disable the slot if you don't want it triggering.

By default, app settings also apply to apps running in deployment slots. You can, however, override the app setting used by the slot by setting a slot-specific app setting. For example, you might want a function to be active in production but not during deployment testing, such as a timer triggered function.

https://learn.microsoft.com/en-us/azure/azure-functions/disable-function?tabs=portal#functions-in-a-slot

Altering the code of the slot to refer to a test queue should work as well, but then you would need to change it back before swapping if you plan to swap. I don't know how the queue trigger specifically behaves but I would assume that 2 messages will be passed to the queue (1 from main Function and 1 from slot).

This thread also describes an issue where main Function and slot triggered off Service Bus. https://github.com/MicrosoftDocs/azure-docs/issues/49834