taipy.enterprise.Scheduler
Taipy Scheduler.
A scheduler for periodic methods that lets you run Taipy functions (or any other Python callable) periodically at pre-determined intervals using a simple, human-friendly syntax.
Features:
- A simple-to-use API for scheduling methods.
- Run pending methods on the background thread.
- Allow to schedule methods by seconds, minutes, hours, days, weeks, months, or even years.
- Allow to schedule methods to run at a specific time on a specific date.
- Allow to stop the schedule until a certain time.
Usage:
import taipy as tp
from taipy import Config, Scheduler
# Configure your Taipy application
...
my_scenario_config = Config.configure_scenario("my_scenario", [task_config])
# Schedule creating a scenario every 10 minutes
Scheduler.every(10).minutes.do(tp.create_scenario, my_scenario_config)
# Schedule creating and submitting a scenario every day at 10:30
Scheduler.every().day.at("10:30").do_create_and_submit_scenario(my_scenario_config)
Scheduler.start()
# Do other stuff...
Scheduler.stop()
cancel_scheduled_method(scheduled_method)
classmethod
¶
Cancel a scheduled method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scheduled_method |
ScheduledMethod
|
The scheduled method to be unscheduled. |
required |
clear(tag=None)
classmethod
¶
Gets scheduled methods marked with the given tag, or all methods if tag is omitted.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tag |
Optional[Hashable]
|
An identifier used to identify a subset of scheduled methods to retrieve. |
None
|
every(interval=1)
classmethod
¶
Schedule a new periodic method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval |
int
|
A quantity of a certain time unit. Defaults to 1. |
1
|
Returns:
Name | Type | Description |
---|---|---|
ScheduledMethod |
ScheduledMethod
|
An un-configured |
get_scheduled_methods(tag=None)
classmethod
¶
Gets scheduled methods marked with the given tag, or all methods if tag is omitted.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tag |
Optional[Hashable]
|
An identifier used to identify a subset of methods to retrieve. |
None
|
next_run(tag=None)
classmethod
¶
Datetime when the next method should run.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tag |
Optional[Hashable]
|
Filter the next run for the given tag parameter. |
None
|
start(interval=60)
classmethod
¶
Start the scheduler in a new thread. Pending scheduled methods are executed at each elapsed time interval.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval |
float
|
Time to wait between each check, in seconds. Defaults to 60. |
60
|
Note
It is intended behavior that run_continuously() does not run missed methods. For example, if you've registered a method that should run every minute and you set a continuous run interval of one hour then your method won't be run 60 time at each interval but only once.
stop(wait=True, timeout=None)
classmethod
¶
Stop the scheduler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wait |
bool
|
If True, the method will wait for the scheduler to stop. |
True
|
timeout |
Optional[float]
|
The maximum time to wait. If None, the method will wait indefinitely. |
None
|