Skip to content

Commit 5d8d69f

Browse files
committed
docs: docstrings for schedules and intervals
1 parent 3460528 commit 5d8d69f

File tree

3 files changed

+210
-1
lines changed

3 files changed

+210
-1
lines changed

tableauserverclient/models/interval_item.py

+40
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33

44
class IntervalItem:
5+
"""
6+
This class sets the frequency and start time of the scheduled item. This
7+
class contains the classes for the hourly, daily, weekly, and monthly
8+
intervals. This class mirrors the options you can set using the REST API and
9+
the Tableau Server interface.
10+
"""
11+
512
class Frequency:
613
Hourly = "Hourly"
714
Daily = "Daily"
@@ -26,6 +33,19 @@ class Day:
2633

2734

2835
class HourlyInterval:
36+
"""
37+
Runs scheduled item hourly. To set the hourly interval, you create an
38+
instance of the HourlyInterval class and assign the following values:
39+
start_time, end_time, and interval_value. To set the start_time and
40+
end_time, assign the time value using this syntax: start_time=time(hour, minute)
41+
and end_time=time(hour, minute). The hour is specified in 24 hour time.
42+
The interval_value specifies how often the to run the task within the
43+
start and end time. The options are expressed in hours. For example,
44+
interval_value=.25 is every 15 minutes. The values are .25, .5, 1, 2, 4, 6,
45+
8, 12. Hourly schedules that run more frequently than every 60 minutes must
46+
have start and end times that are on the hour.
47+
"""
48+
2949
def __init__(self, start_time, end_time, interval_value):
3050
self.start_time = start_time
3151
self.end_time = end_time
@@ -109,6 +129,12 @@ def _interval_type_pairs(self):
109129

110130

111131
class DailyInterval:
132+
"""
133+
Runs the scheduled item daily. To set the daily interval, you create an
134+
instance of the DailyInterval and assign the start_time. The start time uses
135+
the syntax start_time=time(hour, minute).
136+
"""
137+
112138
def __init__(self, start_time, *interval_values):
113139
self.start_time = start_time
114140
self.interval = interval_values
@@ -177,6 +203,15 @@ def _interval_type_pairs(self):
177203

178204

179205
class WeeklyInterval:
206+
"""
207+
Runs the scheduled item once a week. To set the weekly interval, you create
208+
an instance of the WeeklyInterval and assign the start time and multiple
209+
instances for the interval_value (days of week and start time). The start
210+
time uses the syntax time(hour, minute). The interval_value is the day of
211+
the week, expressed as a IntervalItem. For example
212+
TSC.IntervalItem.Day.Monday for Monday.
213+
"""
214+
180215
def __init__(self, start_time, *interval_values):
181216
self.start_time = start_time
182217
self.interval = interval_values
@@ -214,6 +249,11 @@ def _interval_type_pairs(self):
214249

215250

216251
class MonthlyInterval:
252+
"""
253+
Runs the scheduled item once a month. To set the monthly interval, you
254+
create an instance of the MonthlyInterval and assign the start time and day.
255+
"""
256+
217257
def __init__(self, start_time, interval_value):
218258
self.start_time = start_time
219259

tableauserverclient/models/schedule_item.py

+57
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,63 @@
2020

2121

2222
class ScheduleItem:
23+
"""
24+
Using the TSC library, you can schedule extract refresh or subscription
25+
tasks on Tableau Server. You can also get and update information about the
26+
scheduled tasks, or delete scheduled tasks.
27+
28+
If you have the identifier of the job, you can use the TSC library to find
29+
out the status of the asynchronous job.
30+
31+
The schedule properties are defined in the ScheduleItem class. The class
32+
corresponds to the properties for schedules you can access in Tableau
33+
Server or by using the Tableau Server REST API. The Schedule methods are
34+
based upon the endpoints for jobs in the REST API and operate on the JobItem
35+
class.
36+
37+
Parameters
38+
----------
39+
name : str
40+
The name of the schedule.
41+
42+
priority : int
43+
The priority of the schedule. Lower values represent higher priority,
44+
with 0 indicating the highest priority.
45+
46+
schedule_type : str
47+
The type of task schedule. See ScheduleItem.Type for the possible values.
48+
49+
execution_order : str
50+
Specifies how the scheduled tasks should run. The choices are Parallel
51+
which uses all avaiable background processes for a scheduled task, or
52+
Serial, which limits the schedule to one background process.
53+
54+
interval_item : Interval
55+
Specifies the frequency that the scheduled task should run. The
56+
interval_item is an instance of the IntervalItem class. The
57+
interval_item has properties for frequency (hourly, daily, weekly,
58+
monthly), and what time and date the scheduled item runs. You set this
59+
value by declaring an IntervalItem object that is one of the following:
60+
HourlyInterval, DailyInterval, WeeklyInterval, or MonthlyInterval.
61+
62+
Attributes
63+
----------
64+
created_at : datetime
65+
The date and time the schedule was created.
66+
67+
end_schedule_at : datetime
68+
The date and time the schedule ends.
69+
70+
id : str
71+
The unique identifier for the schedule.
72+
73+
next_run_at : datetime
74+
The date and time the schedule is next run.
75+
76+
state : str
77+
The state of the schedule. See ScheduleItem.State for the possible values.
78+
"""
79+
2380
class Type:
2481
Extract = "Extract"
2582
Flow = "Flow"

tableauserverclient/server/endpoint/schedules_endpoint.py

+113-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ def siteurl(self) -> str:
3030

3131
@api(version="2.3")
3232
def get(self, req_options: Optional["RequestOptions"] = None) -> tuple[list[ScheduleItem], PaginationItem]:
33+
"""
34+
Returns a list of flows, extract, and subscription server schedules on
35+
Tableau Server. For each schedule, the API returns name, frequency,
36+
priority, and other information.
37+
38+
REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_jobs_tasks_and_schedules.htm#query_schedules
39+
40+
Parameters
41+
----------
42+
req_options : Optional[RequestOptions]
43+
Filtering and paginating options for request.
44+
45+
Returns
46+
-------
47+
Tuple[List[ScheduleItem], PaginationItem]
48+
A tuple of list of ScheduleItem and PaginationItem
49+
"""
3350
logger.info("Querying all schedules")
3451
url = self.baseurl
3552
server_response = self.get_request(url, req_options)
@@ -38,7 +55,22 @@ def get(self, req_options: Optional["RequestOptions"] = None) -> tuple[list[Sche
3855
return all_schedule_items, pagination_item
3956

4057
@api(version="3.8")
41-
def get_by_id(self, schedule_id):
58+
def get_by_id(self, schedule_id: str) -> ScheduleItem:
59+
"""
60+
Returns detailed information about the specified server schedule.
61+
62+
REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_jobs_tasks_and_schedules.htm#get-schedule
63+
64+
Parameters
65+
----------
66+
schedule_id : str
67+
The ID of the schedule to get information for.
68+
69+
Returns
70+
-------
71+
ScheduleItem
72+
The schedule item that corresponds to the given ID.
73+
"""
4274
if not schedule_id:
4375
error = "No Schedule ID provided"
4476
raise ValueError(error)
@@ -49,6 +81,20 @@ def get_by_id(self, schedule_id):
4981

5082
@api(version="2.3")
5183
def delete(self, schedule_id: str) -> None:
84+
"""
85+
Deletes the specified schedule from the server.
86+
87+
REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_jobs_tasks_and_schedules.htm#delete_schedule
88+
89+
Parameters
90+
----------
91+
schedule_id : str
92+
The ID of the schedule to delete.
93+
94+
Returns
95+
-------
96+
None
97+
"""
5298
if not schedule_id:
5399
error = "Schedule ID undefined"
54100
raise ValueError(error)
@@ -58,6 +104,23 @@ def delete(self, schedule_id: str) -> None:
58104

59105
@api(version="2.3")
60106
def update(self, schedule_item: ScheduleItem) -> ScheduleItem:
107+
"""
108+
Modifies settings for the specified server schedule, including the name,
109+
priority, and frequency details on Tableau Server. For Tableau Cloud,
110+
see the tasks and subscritpions API.
111+
112+
REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_jobs_tasks_and_schedules.htm#update_schedule
113+
114+
Parameters
115+
----------
116+
schedule_item : ScheduleItem
117+
The schedule item to update.
118+
119+
Returns
120+
-------
121+
ScheduleItem
122+
The updated schedule item.
123+
"""
61124
if not schedule_item.id:
62125
error = "Schedule item missing ID."
63126
raise MissingRequiredFieldError(error)
@@ -71,6 +134,20 @@ def update(self, schedule_item: ScheduleItem) -> ScheduleItem:
71134

72135
@api(version="2.3")
73136
def create(self, schedule_item: ScheduleItem) -> ScheduleItem:
137+
"""
138+
Creates a new server schedule on Tableau Server. For Tableau Cloud, use
139+
the tasks and subscriptions API.
140+
141+
Parameters
142+
----------
143+
schedule_item : ScheduleItem
144+
The schedule item to create.
145+
146+
Returns
147+
-------
148+
ScheduleItem
149+
The newly created schedule.
150+
"""
74151
if schedule_item.interval_item is None:
75152
error = "Interval item must be defined."
76153
raise MissingRequiredFieldError(error)
@@ -92,6 +169,41 @@ def add_to_schedule(
92169
flow: Optional["FlowItem"] = None,
93170
task_type: Optional[str] = None,
94171
) -> list[AddResponse]:
172+
"""
173+
Adds a workbook, datasource, or flow to a schedule on Tableau Server.
174+
Only one of workbook, datasource, or flow can be passed in at a time.
175+
176+
The task type is optional and will default to ExtractRefresh if a
177+
workbook or datasource is passed in, and RunFlow if a flow is passed in.
178+
179+
REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_jobs_tasks_and_schedules.htm#add_workbook_to_schedule
180+
REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_jobs_tasks_and_schedules.htm#add_data_source_to_schedule
181+
REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_flow.htm#add_flow_task_to_schedule
182+
183+
Parameters
184+
----------
185+
schedule_id : str
186+
The ID of the schedule to add the item to.
187+
188+
workbook : Optional[WorkbookItem]
189+
The workbook to add to the schedule.
190+
191+
datasource : Optional[DatasourceItem]
192+
The datasource to add to the schedule.
193+
194+
flow : Optional[FlowItem]
195+
The flow to add to the schedule.
196+
197+
task_type : Optional[str]
198+
The type of task to add to the schedule. If not provided, it will
199+
default to ExtractRefresh if a workbook or datasource is passed in,
200+
and RunFlow if a flow is passed in.
201+
202+
Returns
203+
-------
204+
list[AddResponse]
205+
A list of responses for each item added to the schedule.
206+
"""
95207
# There doesn't seem to be a good reason to allow one item of each type?
96208
if workbook and datasource:
97209
warnings.warn("Passing in multiple items for add_to_schedule will be deprecated", PendingDeprecationWarning)

0 commit comments

Comments
 (0)