John P
John P

Reputation: 1221

Python APScheduler, execute an interval between start_date and end_date

I have the following code snippet:

scheduler = TornadoScheduler()
scheduler.add_job(tick2, 'interval', seconds=6)

scheduler.start()

How is it possible to configure a job to be executed on an interval of 5 seconds, but starting on date x at hour x1, and ending on date y at hour y2?

For example starting from 22th of Nov 14:30 and ending by 25th of November 23:00, it will execute a function every 5 seconds?

Thank you!

Upvotes: 1

Views: 1460

Answers (1)

Muhammad Ihfazhillah
Muhammad Ihfazhillah

Reputation: 364

From interval trigger documentation, you can pass start_date and end_date as keyword arguments

So, your code should be

start_date = ... # can be string or datetime object
end_date = ... # can be a string or a datetime object
scheduler.add_job(tick2, 'interval', seconds=6, start_date=start_date, end_date=end_date)

Upvotes: 3

Related Questions