首页 > 解决方案 > HTTP 502:当一个函数与另一个计划函数保持温暖时

问题描述

我有一个 HTTP 触发的消费计划 Azure 函数,我想通过定期向它发布一个空的有效负载来保持温暖。

我正在使用具有此配置的计划函数执行此操作:

__init__.py

import os
import datetime
import logging

import azure.functions as func

import urllib.parse, urllib.request, urllib.error

def main(mytimer: func.TimerRequest) -> None:
    try:
        url = f"https://FUNCTIONNAME.azurewebsites.net/api/predictor?code={os.environ['CODE']}"
        request = urllib.request.Request(url, {})
        response = urllib.request.urlopen(request)
    except urllib.error.HTTPError as e:
        message = e.read().decode()
        if message == "expected outcome":
            pass
        else:
            logging.info(f"Error: {message}")

函数.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "mytimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 */9 5-17 * * 1-5"
    }
  ]
}

当我检查我的日志时,它们充满了 HTML。这是 HTML 的一个片段:

...
<h1>Server Error</h1>
...
<h2>502 - Web server received an invalid response while acting as a gateway or proxy server.</h2>
<h3>There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.</h3>

在本地运行__init__.py的逻辑可以正常工作。这里可能有什么问题?

标签: azureazure-functions

解决方案


嗯……这很奇怪。看起来响应无法路由到我猜的正确实例。

顺便说一句,我相信您可以在与您想要保暖的功能应用程序相同的功能应用程序中简单地使用时间触发功能。这个函数真的不需要做任何事情。

此外,您可能想查看支持预热实例的Azure Functions Premium 。请注意,这仍处于预览阶段。


推荐阅读