0

PS: Complete beginner here.

Because of some restrictions in the company policies, I am not able to test this function locally. However I was able to deploy the function to our functionapp.

I have a init.py which looks like below :

import datetime
import logging

import azure.functions as func


def main(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('Hello!!')
    logging.info('Python timer trigger function ran at %s', utc_timestamp)

The function.json looks like below :

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "mytimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "* * * * *"
    }
  ]
}

I expect the log statements to be shown every minute, but that does not seem to be the case. Output: Output response

What am I inspecting wrong here?

RCB
  • 479
  • 1
  • 9
  • 1
    Your function.json is set to wring CRON, Use "0 */1 * * * *" to run your Timer Trigger function every minute – SiddheshDesai Aug 07 '23 at 07:39
  • 1
    Refer this Ms Document for validation- Schedule 0 */1 * * * * A six field CRON expression that schedules your function to run every minute. - https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-scheduled-function#create-a-timer-triggered-function – SiddheshDesai Aug 07 '23 at 07:39
  • I made the changes, however still the logs are not seen :( Am i correct in expecting logs in the black window I shared? – RCB Aug 07 '23 at 07:51
  • Select Log Level to Information and rerun the Function, Refer my answer on checking Azure Functions logs here- https://stackoverflow.com/questions/76452253/how-can-i-view-error-logs-from-a-python-azure-function-app/76453842# – SiddheshDesai Aug 07 '23 at 07:55

1 Answers1

1

I created one Azure Function Timer Trigger with CRON scheduleset to 0 */1 * * * *

My function.json:-

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

Locally the Function runs every minute:-

enter image description here

I deployed the function on Azure Portal and received logs for every minute the Timer Trigger Function was executed.

enter image description here

enter image description here

With Log Level set to verbose:-

enter image description here

If the Logs are not loading, Make sure you have enabled Application Insights for your Function app:-

enter image description here

The Logs are also stored in your storage account that is created with your Azure Function app, Make sure your organisational Firewall or other restrictions are not avoiding you from connecting to storage account or Application Insights. If you are connected to any corporate proxy or VPN, Try to remove the restrictions or deploy your function app inside a VNet and allow storage account and your Firewall IP to access the Function app, For more information on Azure Functions with Vnet refer How to configure Azure Functions with a virtual network | Microsoft Learn

Additionally refer the SO thread answers if your Function Logs are not loading properly.

SiddheshDesai
  • 3,668
  • 1
  • 2
  • 11
  • Thank you for the insights, one other question: Just like the command to create a simple HTTP trigger function : ```func new --name HttpExample --template "HTTP trigger" --authlevel "anonymous" ```, is it possible to create a time triggred function with a cron schedule of every minute? I tried with : ``` func new --name TimeTrigger --template "Timer trigger" --schedule "0 */1 * * * *" ``` . but it shows a default schedule of ``` 0 */5 * * * * ``` – RCB Aug 09 '23 at 06:45