Azure Function 在部署后偶尔仍运行旧代码

标签 azure azure-devops azure-functions

有时,在将最新位部署到 azure 函数后,它仍然运行该函数的旧版本。以下是 .NET core azure 函数和部署代码的构建。关于造成这种情况的原因的想法。部署过程中没有出现任何故障,只是偶尔发生。我尝试为 azure 功能添加重新启动步骤,但无济于事。作为临时解决方案,我完全删除了 azure 函数并在构建过程中重新创建它,但这不太理想。

//ARM 函数

    {
  "apiVersion": "2015-08-01",
  "type": "Microsoft.Web/sites",
  "name": "[variables('functionAppName')]",
  "location": "[parameters('location')]",
  "kind": "functionapp",
  "dependsOn": [
    "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
    "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]",
    "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccounts_calculationartifacts_name'))]"
  ],
  "properties": {
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
    "siteConfig": {
      "appSettings": [
        {
          "name": "AzureWebJobsStorage",
          "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
        },
        {
            "name": "AzureWebJobsDashboard",
            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
        },
        {
          "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
          "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
        },
        {
          "name": "WEBSITE_CONTENTSHARE",
          "value": "[toLower(variables('functionAppName'))]"
        },
        {
          "name": "FUNCTIONS_EXTENSION_VERSION",
          "value": "~3"
        },
        {
          "name": "WEBSITE_NODE_DEFAULT_VERSION",
          "value": "~10"
        },
        {
          "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
          "value": "[reference(resourceId('microsoft.insights/components/', variables('applicationInsightsName')), '2015-05-01').InstrumentationKey]"
        },
        {
          "name": "FUNCTIONS_WORKER_RUNTIME",
          "value": "[variables('functionWorkerRuntime')]"
        },
        {
          "name": "WEBSITE_ENABLE_SYNC_UPDATE_SITE",
          "value": "true",
          "slotSetting": false
        }
      ]
    }
  }
}

//yaml 构建步骤

- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    command: 'build'
    projects: |
      **/$(myProject).csproj
    arguments: --output $(System.DefaultWorkingDirectory)/publish_output --configuration Release

//yaml 部署步骤

      - task: AzureFunctionApp@1
        displayName: 'Azure functions app deploy'
        inputs:
          azureSubscription: '$(azureSubscription)'
          appType: functionApp
          appName: $(myAppName)
          package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'

最佳答案

可能是您的函数长时间运行。对该函数的调用将运行调用该函数时可用的代码版本。

场景1:

  • T0:有电话进来,函数的 V1 开始运行
  • T1:功能 V2 已部署
  • T2:使用函数的 V1 完成调用

场景 2:

  • T0:函数的 V1 正在运行
  • T1:开始部署 V2
  • T2:调用进来,因为 V2 部署尚未完成,V1 响应

如果该函数在部署几分钟后仍然以 V1 响应,则说明存在其他问题。

关于Azure Function 在部署后偶尔仍运行旧代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62104578/

相关文章:

azure-devops - Azure Devops Nuget 还原失败并显示 "unable to load the service index for source"

azure-functions - 如何延迟读取触发器 HTTP 请求的正文,直到稍后在 Azure 函数中?

wordpress - 我身处 Azure、CORS 和 WOFF hell

azure - 如何管理 Azure Durable Functions 的执行历史记录

azure - 在 Azure Pipeline 中使用 terraform 进行 ArgoCD 引导

c# - 当我从 AWS 迁移到 Azure Data Lake 时,如何避免存储此文件?

触发的 Azure Function 3.0 服务总线有时会引发 Microsoft.Azure.ServiceBus.MessageLockLostException

javascript - 返回时 Microsoft.Azure.WebJobs.Script : Unable to cast object of type 'System.String' to type 'Microsoft.AspNetCore.Http.HttpRequest' .

Azure Function App 代理正在删除查询字符串

php - 使用 Azure Web 应用程序连接到 Azure 数据库