question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TimeTrigger Azure Function Python API pass ScheduleStatus to function

See original GitHub issue

What problem would the feature you’re requesting solve? Please describe.

The TimeTrigger Function pass a TimerRequest[1] object to the executed function. Unlike in the C# interface, the only property of the TimerRequest object is the past_due attribute.

Describe the solution you’d like

Pass all the information, which are discussed and listed in [2], e.g. the ScheduleStatus.

{` "Schedule":{ }, "ScheduleStatus": { "Last":"2016-10-04T10:15:00+00:00", "LastUpdated":"2016-10-04T10:16:00+00:00", "Next":"2016-10-04T10:20:00+00:00" }, "IsPastDue":false }

[1]https://docs.microsoft.com/de-de/python/api/azure-functions/azure.functions.timerrequest?view=azure-python [2]https://docs.microsoft.com/de-de/azure/azure-functions/functions-bindings-timer?tabs=csharp

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
finn-wacommented, Nov 21, 2020

As a workaround, you can set the input parameter to be str. Then you get all of the data in JSON format, and you can make your own class if you wish. For example: function.json

{
  "scriptFile": "sample.py",
  "bindings": [
    {
      "direction": "in",
      "type": "timerTrigger",
      "name": "timerJson",
      "schedule": "0 0 3 * * *"
    }
  ]
}

sample.py

import logging
from timer_request import TimerRequest

def main(timerJson: str):
    timer = TimerRequest(timerJson)
    if timer.past_due:
        logging.warn("Timer is past due!")
    logging.info(timer.schedule_status.last)

timer_request.py

import json
from datetime import datetime
from dateutil import parser

class ScheduleStatus:
    """
    Represents a timer schedule status.
    - last: Last recorded schedule occurrence
    - next: Expected next schedule occurrence
    - last_updated: The last time this record was updated. This is used to
      re-calculate Next with the current Schedule after a host restart.
    """

    last: datetime
    next: datetime
    last_updated: datetime

    def __init__(self, json_dict: dict):
        self.last = parser.isoparse(json_dict["Last"])
        self.next = parser.isoparse(json_dict["Next"])
        self.last_updated = parser.isoparse(json_dict["LastUpdated"])


class TimerRequest:
    """
    A more complete version of the TimerRequest with a ScheduleStatus.
    """

    schedule_status: ScheduleStatus
    past_due: bool

    def __init__(self, json_str: str):
        json_dict = json.loads(json_str)
        self.schedule_status = ScheduleStatus(json_dict["ScheduleStatus"])
        self.past_due = json_dict["IsPastDue"]
1reaction
KhaoticMindcommented, Jan 4, 2022

Any update on this issue? The workaround works as described but is a workaround, the timer parameter should work as documented.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Timer trigger for Azure Functions | Microsoft Learn
This article explains how to work with timer triggers in Azure Functions. A timer trigger lets you run a function on a schedule....
Read more >
Timer trigger Azure function - How to get datetime details of ...
So the 'Last' means the time you last trigger the function, no matter success or failure. And ScheduleStatus = new ScheduleStatus { Last ......
Read more >
Azure Functions in Python | HTTP Triggers Pt. 1 - YouTube
With a high level overview of Azure functions under our belt we are going to ... video which covers how to create a...
Read more >
Tutorial of Python Azure functions - Towards Data Science
Tutorial of Python Azure functions. Publish your code as an API without the traditional server setup. Introduction. Azure functions is a “serverless solution” ......
Read more >
Understanding TimerTriggers in Azure Functions
The more triggers are fired on the Azure Function, the more functions are executed. If you choose for a consumption plan this can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found