问题描述
函数可以知道它是否在插槽中运行吗?
Can a function know if it's running in a slot?
如果要在暂存"状态下执行某项功能,我想阻止该功能被执行.插槽.
I would like to prevent a function to be executed if in "staging" slot.
基于布鲁斯的回答(再次感谢伙伴),我写了那篇博客文章 http://www.frankysnotes.com/2017/09/how-to-know-when-azure-function-is.html
Base on the answer from Bruce (thanks again buddy), I wrote that blog post http://www.frankysnotes.com/2017/09/how-to-know-when-azure-function-is.html
推荐答案
据我了解,您可以检查代码中的APPSETTING_WEBSITE_SLOT_NAME
环境变量,当函数处于生产状态时,该值将为 Production (生产),而当函数处于生产状态时,该值将为插槽名称.在以下插槽中:
Per my understanding, you could check the APPSETTING_WEBSITE_SLOT_NAME
environment variable in your code, and the value would be Production when your function is under production while the value would be the slot name when your function is under a slot as follows:
对于C#,您可以利用以下代码来检索此变量:
For C#, you could leverage the following code for retrieving this variable:
System.Environment.GetEnvironmentVariable("APPSETTING_WEBSITE_SLOT_NAME", EnvironmentVariableTarget.Process);
此外,对于F#,您可以参考此处,对于JavaScript,您可以参考此处.
Additionally, for F# you could refer to here, for JavaScript you could refer to here.
这篇关于如何知道Azure功能是否正在插槽中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!