schedule_ module¶
Utilities for scheduling jobs.
AsyncJob class¶
Async CustomJob.
Superclasses
- CustomJob
schedule.Job
async_run method¶
Async CustomJob.run.
AsyncScheduler class¶
Async CustomScheduler.
Superclasses
- CustomScheduler
schedule.Scheduler
async_run_all method¶
Async CustomScheduler.run_all.
async_run_pending method¶
Async CustomScheduler.run_pending.
every method¶
Schedule a new periodic job of type AsyncJob.
CancelledError class¶
Thrown for the operation to be cancelled.
Superclasses
asyncio.exceptions.CancelledErrorbuiltins.BaseException
CustomJob class¶
A periodic job as used by :class:Scheduler.
:param interval: A quantity of a certain time unit :param scheduler: The :class:Scheduler <Scheduler> instance that this job will register itself with once it has been fully configured in :meth:Job.do().
Every job runs at a given fixed time interval that is defined by:
- a :meth:
time unit <Job.second> - a quantity of
time unitsdefined byinterval
A job is usually created and returned by :meth:Scheduler.every method, which also defines its interval.
Superclasses
schedule.Job
Subclasses
force_missed_run property¶
modulo property¶
zero_offset property¶
CustomScheduler class¶
Objects instantiated by the :class:Scheduler <Scheduler> are factories to create jobs, keep record of scheduled jobs and handle their execution.
Superclasses
schedule.Scheduler
Subclasses
ScheduleManager class¶
Class that manages CustomScheduler.
async_start method¶
Async run pending jobs in a loop.
async_task property¶
Current async task.
async_task_running property¶
Whether the async task is running.
clear_jobs method¶
Delete scheduled jobs with the given tags, or all jobs if tag is omitted.
done_callback method¶
Callback run when the async task is finished.
every method¶
Create a new job that runs every interval units of time.
*args can include at most four different arguments: interval, unit, start_day, and at, in the strict order:
interval: integer ordatetime.timedeltaunit: ScheduleManager.unitsstart_day: ScheduleManager.weekdaysat: string ordatetime.time.
See the package schedule for more details.
Usage
>>> from vectorbtpro import *
>>> def job_func(message="I'm working..."):
... print(message)
>>> my_manager = vbt.ScheduleManager()
>>> # add jobs
>>> my_manager.every().do(job_func, message="Hello")
Every 1 second do job_func(message='Hello') (last run: [never], next run: 2021-03-18 19:06:47)
>>> my_manager.every(10, 'minutes').do(job_func)
Every 10 minutes do job_func() (last run: [never], next run: 2021-03-18 19:16:46)
>>> my_manager.every(10, 'minutes', ':00', zero_offset=True).do(job_func)
Every 10 minutes at 00:00:00 do job_func() (last run: [never], next run: 2022-08-18 16:10:00)
>>> my_manager.every('hour').do(job_func)
Every 1 hour do job_func() (last run: [never], next run: 2021-03-18 20:06:46)
>>> my_manager.every('hour', '00:00').do(job_func)
Every 1 hour at 00:00:00 do job_func() (last run: [never], next run: 2021-03-18 20:00:00)
>>> my_manager.every(4, 'hours', '00:00').do(job_func)
Every 4 hours at 00:00:00 do job_func() (last run: [never], next run: 2021-03-19 00:00:00)
>>> my_manager.every('10:30').do(job_func)
Every 1 day at 10:30:00 do job_func() (last run: [never], next run: 2021-03-19 10:30:00)
>>> my_manager.every('hour', '00:00').do(job_func)
Every 1 hour at 00:00:00 do job_func() (last run: [never], next run: 2021-03-19 10:30:00)
>>> my_manager.every(4, 'hour', '00:00').do(job_func)
Every 4 hours at 00:00:00 do job_func() (last run: [never], next run: 2021-03-19 10:30:00)
>>> my_manager.every('day', '10:30').do(job_func)
Every 1 day at 10:30:00 do job_func() (last run: [never], next run: 2021-03-19 10:30:00)
>>> my_manager.every('day', time(9, 30, tzinfo="utc")).do(job_func)
Every 1 day at 10:30:00 do job_func() (last run: [never], next run: 2021-03-19 10:30:00)
>>> my_manager.every('monday').do(job_func)
Every 1 week do job_func() (last run: [never], next run: 2021-03-22 19:06:46)
>>> my_manager.every('wednesday', '13:15').do(job_func)
Every 1 week at 13:15:00 do job_func() (last run: [never], next run: 2021-03-24 13:15:00)
>>> my_manager.every('minute', ':17').do(job_func)
Every 1 minute at 00:00:17 do job_func() (last run: [never], next run: 2021-03-18 19:07:17)
>>> my_manager.start()
You can still use the chained approach as done by schedule:
>>> my_manager.every().minute.at(':17').do(job_func)
Every 1 minute at 00:00:17 do job_func() (last run: [never], next run: 2021-03-18 19:07:17)
scheduler property¶
Scheduler.
start method¶
Run pending jobs in a loop.
start_in_background method¶
Run ScheduleManager.async_start() in the background.
stop method¶
Stop the async task.