I want to schedule a python function to run everyday at a certain time for a list of customers with different timezones.
This is basically what I want to do:
import schedule
import time
def job(text):
print("Hello " + text)
def add_job(user_tz, time, text):
schedule.every().day.at(time).do(job(text))
# the above adds all jobs at local time, I want to use different timezones with these
def run_job():
while(1):
schedule.run_pending()
time.sleep(1)
if __name__=='__main__':
add_job('America/New_York', "12:00", 'New York')
add_job('Europe/London', "12:00", 'London')
run_job()
I am using this for posting/receiving some stuff using flask and an external API.
Celery or heroku scheduler or something heavy is not what I am looking for, something lightweight and pythonic for debian(or nix) env would be ideal. I have looked into scheduler, tzcron and APScheduler, but could not figure out how we would be able to use them with timezones.
Also I tried using crontab but could not figure out how to add jobs at run time, since I want to be able to add/remove jobs using the above mentioned functions at runtime as well.
I have some experience with python, but its my first problem with timezones and I dont know much about this, so please feel free to enlighten me if there is something I missed or if there is any other way of doing it.
Thanks!