连续 Azure Web 作业在交换到新插槽后是否会重新启动?

Does a continuous Azure web job restart after being swapped to a new slot?

当我在 Azure 中交换部署槽时,Web 作业会重新启动吗?如果是,它们是使用目标配置值还是源配置值重新启动?

在我的例子中,我不希望 Web 作业 运行 在暂存槽中。为了解决这个问题,我有以下代码:

public static void Main()
{
    // Only run web jobs when configured
    bool enableWebJobs = false;
    bool.TryParse(ConfigurationManager.AppSettings["EnableWebJobs"], out enableWebJobs);

    if (enableWebJobs)
    {
        var host = new JobHost();
        host.RunAndBlock();
    }
    else
    {
        // Sleep so the Azure web jobs platform doesn't try to continually restart the process
        while (true)
        {
            Thread.Sleep(60000);
        }
    }
}

我只是不确定在使用正确的 AppSettings 交换后网络作业是否会重新启动。如果不是,那么这根本不起作用,因为 EnableWebJobs 将保持为 false。

配置也被交换,因此您的代码将无法按您希望的那样工作。

使用 Amit Apple 的 post

To prevent WebJobs from running on the staging slot you can add an app setting called WEBJOBS_STOPPED and set it to 1 (in the azure portal)

我已使用此粘性插槽设置在暂存中禁用了网络作业。

查看 Kudu 面板中的 webjobs 日志,webjobs 在部署应用程序时启动并且不受实际交换的影响(AFAIK 只是路由到新 live/stage 的负载均衡器) .

编辑:我错了。有一个重新启动作为交换的一部分。 (见Understanding site swaps)即:

这是将源插槽(我们称之为 'Staging')交换到目标插槽(生产)时发生的情况。

  1. 首先,登台站点需要进行一些设置更改 标记为 'slot' 的应用程序设置和连接字符串。那里 还有其他与源代码管理相关的更改可能需要 应用。 这会导致暂存站点重新启动,这很好。

  2. 接下来,通过将请求发送到 它的根路径(即“/”),并等待它完成。

  3. 现在暂存站点是热的,它被交换到生产站点。 没有停机时间,因为它直接从一个温暖的站点到 另一个.

  4. 最后,原来是Production的站点,现在也是Staging了 需要应用一些设置,导致它重新启动。再一次,这个 很好,因为它发生在暂存站点中。