0

i have one httpTrigger where i have implemented cache we have a requirement where we have to update cache after 2 hr.

Solution 1: we can expire the cache after 2 hour.. but we don't want to use this solution

Solution 2: we want a function to get triggered (update_cache()) after every 2 hour.

I find out some library But i am unable to get how i can implement this..

# i want to trigger this function every 2 hour
def trigger_scheduler_update():
    logging.info("Hi i am scheduler and got triggered...")
schedule.every(2).hours.do(trigger_scheduler_update)

But the problem i am facing here is we have to write this kind of code.

# ref: https://www.geeksforgeeks.org/python-schedule-library/
while True: 
  
    # Checks whether a scheduled task  
    # is pending to run or not 
    schedule.run_pending() 
    time.sleep(1) 

As its an infinite loop i can place it in http trigger is there a way i can implement a scheduler that run after 2 hr.

i don't know that can it be done using threading? i found one more library but looks like it also won't work.

Mohit Singh
  • 401
  • 1
  • 10
  • 30

1 Answers1

0

Your function is shut down after a period of time, unless you are on a premium plan. Even then you cannot guarantee your function keeps on running.

What cache are you referring to?

Note that you cannot do threading in azure functions and you shouldn't actually. Abandon the idea of refreshing the cache from your httpTrigger function and create a separate scheduleTriggered function to update the cache that your http function is using.

JarroVGIT
  • 4,291
  • 1
  • 17
  • 29
  • we have a premium plan and we are using azure redis cache.. if i want to do this there is no direct way? without writing timeTrigger – Mohit Singh Aug 03 '20 at 09:51
  • So, you have a httpTriggered Azure Function that reads something from a Redis Cache and returns that in the response when the httpTriggered function is called? And you run this cache in the function?? Please elaborate on your architecture as this is impossible to advise on without any more context. For example, are you using Azure Redis Cache? – JarroVGIT Aug 03 '20 at 11:44