I have a timer function in Python, that’s supposed to run daily. However there is a business requirement that a certain method runs on a monthly basis.
Is there a way for me to do this?
It would be something like the following in pseudo code:
next_monthly_job = date + "30d"
def main (timer):
if current_date != next_monthly_job:
## do normal stuff
elif:
## do specific monthly stuff
next_monthly_job = current_date + "30d"
I’m just concerned that the global variable will be overwritten at each trigger, hence never reaching the else statement.
Thanks in advance!
2
Answers
I suppose you’re gonna use Azure Function App. Then it is easy – just configure time trigger (https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-timer?tabs=python-v2%2Cin-process&pivots=programming-language-python) for your function. Create two functions, and set the corresponding triggers for each of those.
You can run your Function every month by setting the function.json like below:-
And In your function init.py, check the current date to see if you want to execute the regular or customized monthly stuff. To determine whether the timer is past due, utilise the isPastDue property.
Code:-
Output:-