1

I'm a beginner with Azure App Function. I want my python code to run every day automatically in a specific hour (1AM) and App function with the tool 'timer trigger' could allow it.

I created my app function in VS code and it successfully appeared on my azure account. BUT I can't visualize my python code or the timer trigger I try to implement.

Here is a part of my function_app.py :

import azure.functions as func

app = func.FunctionApp()

@app.timer_trigger(schedule="0 * * * * *", arg_name="myTimer", run_on_startup=False,
              use_monitor=False) 

def run_api_function():
    #My code displayed to call an API


def timer_trigger_test(myTimer: func.TimerRequest) -> None:
    if myTimer.past_due:
        logging.info('The timer is past due!')
    run_api_function()
    logging.info('Python timer trigger function executed.')

I would like to know the step to implement my code and I welcome any advices !

About what I already tried, I have succesffuly start my code in VSCode in local with azure.

I tried to deploy it many times but it never appeared in the files of my app function in azure webpage.

It also not appeared in the azure ressources displayed in VScode.

0

1 Answer 1

0

Based on the documentation I can find online, I believe the primary issue is the placement of your @app.timer_trigger decorator: that decorator needs to be before the function that actually should be triggered, which in your case is the timer_trigger_test function, not before the run_api_function function.

Secondarily, the schedule is incorrect for the desired timing of "every day at 1am". for that, the schedule should be "0 0 1 * * *".

Finally, you're missing the import for the logging module.

import azure.functions as func
import logging

app = func.FunctionApp()

def run_api_function():
    #My code displayed to call an API

@app.timer_trigger(schedule="0 0 1 * * *",
                   arg_name="myTimer",
                   run_on_startup=False,
                   use_monitor=False) 
def timer_trigger_test(myTimer: func.TimerRequest) -> None:
    if myTimer.past_due:
        logging.info('The timer is past due!')
    run_api_function()
    logging.info('Python timer trigger function executed.')```

see https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=python-v2%2Cisolated-process%2Cnodejs-v4&pivots=programming-language-csharp#ncrontab-expressions for information about the crontab schedule.

see https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=python-v2%2Cisolated-process%2Cnodejs-v4&pivots=programming-language-python#example for an example for using the timer as a trigger.

Caveat: I have never worked with Azure, so this is going purely off the Azure API documentation.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks you for the reply ! Yes, my apologies for the CRON, to test the app, I changed the Cron to run every minutes to instantly know if it runs. I consulted the documentation using timer as a trigger. I started a new App and tried to follow the guide but I can see that I don't have the possiblity to use the same path as the guide is advicing...
I don't have the opportunity to create a function from Azure portal in my app function. I'm wandering if it is a subscription allowance issue :/ Do you know if the free account is enough to allow to create an app function ?
As I mentioned, I've never worked with Azure. However, from the documentation at learn.microsoft.com/en-us/azure/azure-functions/functions-scale , you need a plan that allows them to charge you for resource utilization.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.