如何知道Azure功能是否正在插槽中运行 [英] How to know if an Azure function is running in a slot

查看:72
本文介绍了如何知道Azure功能是否正在插槽中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

函数可以知道它是否在插槽中运行吗?

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.

已更新

基于布鲁斯的回答(再次感谢伙伴),我写了那篇博客文章

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

推荐答案

函数可以知道它是否在插槽中运行吗?

Can a function know if it's running in a slot?

据我了解,您可以检查代码中的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#,您可以参考此处.

Additionally, for F# you could refer to here, for JavaScript you could refer to here.

这篇关于如何知道Azure功能是否正在插槽中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆