I am trying to deploy an time triggered (schedule) function to azure function using the python v2 model. The function works as expected locally. I am deploying using VSCode and Azurite extension. The deployment seems to be successful, however it says that "No HTTP triggers found" (which does not make any sense because it is not an HTTP triffered function), and the function is in fact not deployed to Azure. What could be wrong here?
function_app.py
import azure.functions as func
import datetime
import logging
import requests
import json
import sys
import os
CRON_SCHEDULE = "*/10 * * * * *"
app = func.FunctionApp()
@app.function_name(name="testSendReqToApiTimeTrigger")
@app.schedule(schedule=CRON_SCHEDULE, arg_name="mytimer", run_on_startup=False, use_monitor=True)
def makeApiCall(mytimer: func.TimerRequest, context: func.Context) -> None:
if mytimer.past_due:
logging.info('The timer is past due!')
logging.info('.context_func_dir: ' + context.function_directory)
url = "http://worldtimeapi.org/api/timezone/Europe/Amsterdam"
try:
response = requests.get(url)
print(f"request completed with status code: {response.status_code}")
except:
logging.error("ERROR during sending request : ")
logging.error(str(sys.exc_info()))
The last few lines of the output of the deployment process:
...
11:24:06 AM test-timer-function: Deployment successful. deployer = ms-azuretools-vscode deploymentPath = Functions App ZipDeploy. Extract zip. Remote build.
11:24:20 AM test-timer-function: Syncing triggers...
11:24:29 AM test-timer-function: Querying triggers...
11:24:34 AM test-timer-function: No HTTP triggers found.
Source Code from the given MS Doc.
import azure.functions as func
import logging
import datetime
app = func.FunctionApp()
@app.function_name(name="mytimer")
@app.schedule(schedule="0 */5 * * * *", arg_name="mytimer", run_on_startup=True,
use_monitor=False)
def test_function(mytimer: func.TimerRequest) -> None:
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
if mytimer.past_due:
logging.info('The timer is past due!')
logging.info('Python timer trigger function ran at %s', utc_timestamp)
When I deploy the Python v2 Timer Triggered Azure Function, it gives the same because the actual local function project does not contain any HTTP Triggered Functions.
But I got the functions in the Azure Function App Portal:
because in the Python V2 programming model, we have to add one application setting explicitly in the Portal Function App Configuration:
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"