Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

azure - Why is my python timer trigger function not running at the correct time?

this is probably a noob question. I have an Azure Function that responds to HTTP requests and it works fine, I can call it from a browser or from a Python 3.8 script.

I want to make another function that will have Timer Trigger and will call the HTTP trigger function on a schedule.

HTTP Trigger function returns a simple string with execution results.

Now my code for Timer trigger function is using Python Requests and it works locally every time, but will work only 1/10 times when deployed to Azure. Other times it returns error when it reaches timeout of 30 minutes. The whole thing should run only for 1-2 minutes max so I don't understand where it gets stuck.

When successful it works(I can see in backend of HTTP trigger script), but in azure logs the logger saves 404 error page html instead of the string that HTTP trigger function should return.

Here is the code for Timer Trigger function:

import datetime
import logging

import azure.functions as func

import requests

def main(mytimer: func.TimerRequest) -> None:
    URL = "https://rob-functions.azurewebsites.net/api/ss_kite_scrape_http"
    r = requests.get(url = URL) 
    data = r.text
    logging.info(f'TIMER TRIGGER HAS RUN. RESULT:{data}')

How to troubleshoot or fix this? The logging issue is not so important but the timeout issue has to be fixed somehow and I have no idea where to start since it works perfectly locally.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

According to some test, I met the issue similar with yours'. I create a HttpTrigger with the default code(I add a line time.sleep(20) in it). And then I create a TimerTrigger(the cron expression is 0 */1 * * * *) with requests module to call the HttpTrigger function. The two functions are in one function app, it seems the issue was caused by the two functions interact with each other but I don't know why. All of the two functions code looks fine.

For a workaround, I create the two functions(HttpTrigger and TimerTrigger) in different function apps and deploy them to two function app in azure. Then it works fine, they will not interact with each other.

Hope it helps~


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...