Azure功能部署会终止我正在运行的进程..我可以避免吗? [英] Azure-Function Deployment kill my running process..can i avoid?
问题描述
我有一些共享相同代码的Azure函数.因此,我创建了一个批处理文件来发布我的库.这是一个简单的蝙蝠文件.对于我的每一种Azure功能,它都连接到主机并使用robocopy来同步文件夹.
I have a few Azure functions sharing same the code. So I created a batch file for publishing my libs. It is a simple bat file. For each of my azure functions, it connects to a host and uses robocopy to synchronize folders.
但是,每次我发布时,都会删除当前正在运行的功能.我想避免这种情况.有没有办法让正在运行的函数自然终止其工作?
However, each time I publish, current running functions are dropped. I want to avoid that. Is there a way to let a running function naturally terminate its work?
我认为这是有可能的,因为在发布时,我没有重写真正运行中的dll,而是将文件复制到<azure-function-url>/site/wwwroot
文件夹中.
I think its possible because when I publish, I'm not re-write real running dll, but I copy file in <azure-function-url>/site/wwwroot
folder.
注意: 该函数无需等待即可调用异步方法.更改源时,异步方法未完成工作. (我不关注这个问题,谢谢马特的评论.睁开眼睛)
NOTE: The function calls an async method without await. The async method does not completed the work when source change. (Im not focus on this problem, thanks Matt for the comment..open my eyes)
推荐答案
The functions runtime is designed to allow functions to gracefully exit in the event of host restarts, see here.
不等待您的异步调用是函数的反模式,因为我们将无法跟踪您的函数执行情况.我们使用返回的Task
来确定您的函数何时完成.如果您不返回Task
,则假定您的函数在返回时已完成.
Not awaiting your async calls is an antipattern in functions, as we won't be able to track your function execution. We use the returned Task
to determine when your function has finished. If you do not return a Task
, we assume your function has completed when it returns.
对于您而言,这意味着当您运行孤立的异步调用时,我们将在重新启动时终止主机.如果您未能等待异步呼叫,我们也不保证会成功:
In your case, that means we will kill the host on restarts while your orphaned asynchronous calls are running. If you fail to await async calls, we also don't guarantee successful:
- 记录
- 输出绑定
- 异常处理
执行:static async Task Run(...){ await asyncMethod(); }
不要:static void Run(...){ asyncMethod(); }
这篇关于Azure功能部署会终止我正在运行的进程..我可以避免吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!