Search code examples
pythonpython-3.xschedulerschedule

Run a job once at the given time in time zone


My code is to schedule a task at specific time to run

from datetime import date
from apscheduler.scheduler import Scheduler

# Start the scheduler
sched = Scheduler()
sched.start()

# Define the function that is to be executed
def my_job(text):
    print(text)

# The job will be executed on May 31, 2021
exec_date = date(2021, 5, 31)

job = sched.add_date_job(my_job, exec_date, ['text'])

So the above code will run on that date. My requirement is to specify all date, time and time-zone at which the function has to run at.


Solution

  • Use crontab or if you want to do within python and not interfere with linux use of schedule library.