Azure Function Works on RunOnStartup but not on Timer Trigger Invocation

Fábio Santos 85 Reputation points
2025-01-20T10:56:41.42+00:00

Hi,

I have Azure Function with timer trigger. This function is running on B3 service plan.

I have configured runOnStartup : True.

When i stop and start the function app, the function will run (because runOnStartup : True) and work as expected. But everytime the function is invoked via timer trigger, the function doesnt work. Gives timeout error when connects to open ai api.

Someone could help me? The runOnStartup environment and timer trigger environment aren't the same?

Regards and Thanks,

Fábio Santos

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,911 questions
0 comments No comments
{count} votes

Accepted answer
  1. Khadeer Ali 5,990 Reputation points Microsoft External Staff Moderator
    2025-01-20T14:29:17.6933333+00:00

    @Fábio Santos ,
    Welcome to Microsoft Q&A Platform!
    Thanks for reaching out.

    Azure Function's timer trigger might be failing due to discrepancies between its execution environment and that of the runOnStartup setting. While runOnStartup executes the function after full initialization of resources, network, and dependencies, the timer trigger can encounter issues like cold starts, network initialization delays, or resource limitations, potentially causing timeouts when connecting to the OpenAI API.

    Here are some potential solutions:

    • Cold Starts: B3 service plan cold starts can introduce significant latency. Consider upgrading to a Premium Plan for more consistent resource allocation and reduced cold start times.
    • Network Initialization: Delays in network initialization can hinder API calls. Implement retry logic and ensure proper network initialization within your function.
    • Resource Constraints: The B3 plan's resource limitations might impact performance. Monitor resource usage and consider scaling up if necessary.
    • Dependency Initialization: Ensure all dependencies are fully initialized before the timer trigger attempts the API call to prevent errors.
    • Timeout Settings: Adjust timeout settings to accommodate potentially longer-running OpenAI API calls.
    • Application Insights: Enable Application Insights for detailed logs and metrics to aid in troubleshooting.

    For more details, you can refer to the official Timer trigger documentation.
    Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.