Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: task docstrings #1527

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tableauserverclient/models/task_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,36 @@


class TaskItem:
"""
Represents a task item in Tableau Server. To create new tasks, see Schedules.

Parameters
----------
id_ : str
The ID of the task.

task_type : str
Type of task. See TaskItem.Type for possible values.

priority : int
The priority of the task on the server.

consecutive_failed_count : int
The number of consecutive times the task has failed.

schedule_id : str, optional
The ID of the schedule that the task is associated with.

schedule_item : ScheduleItem, optional
The schedule item that the task is associated with.

last_run_at : datetime, optional
The last time the task was run.

target : Target, optional
The target of the task. This can be a workbook or a datasource.
"""

class Type:
ExtractRefresh = "extractRefresh"
DataAcceleration = "dataAcceleration"
Expand Down
78 changes: 78 additions & 0 deletions tableauserverclient/server/endpoint/tasks_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ def __normalize_task_type(self, task_type: str) -> str:
def get(
self, req_options: Optional["RequestOptions"] = None, task_type: str = TaskItem.Type.ExtractRefresh
) -> tuple[list[TaskItem], PaginationItem]:
"""
Returns information about tasks on the specified site.

REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_jobs_tasks_and_schedules.htm#list_extract_refresh_tasks

Parameters
----------
req_options : RequestOptions, optional
Options for the request, such as filtering, sorting, and pagination.

task_type : str, optional
The type of task to query. See TaskItem.Type for possible values.

Returns
-------
tuple[list[TaskItem], PaginationItem]

"""
if task_type == TaskItem.Type.DataAcceleration:
self.parent_srv.assert_at_least_version("3.8", "Data Acceleration Tasks")

Expand All @@ -45,6 +63,20 @@ def get(

@api(version="2.6")
def get_by_id(self, task_id: str) -> TaskItem:
"""
Returns information about the specified task.

REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_jobs_tasks_and_schedules.htm#get_extract_refresh_task

Parameters
----------
task_id : str
The ID of the task to query.

Returns
-------
TaskItem
"""
if not task_id:
error = "No Task ID provided"
raise ValueError(error)
Expand All @@ -59,6 +91,21 @@ def get_by_id(self, task_id: str) -> TaskItem:

@api(version="3.19")
def create(self, extract_item: TaskItem) -> TaskItem:
"""
Creates a custom schedule for an extract refresh on Tableau Cloud. For
Tableau Server, use the Schedules endpoint to create a schedule.

REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#create_cloud_extract_refresh_task

Parameters
----------
extract_item : TaskItem
The extract refresh task to create.

Returns
-------
TaskItem
"""
if not extract_item:
error = "No extract refresh provided"
raise ValueError(error)
Expand All @@ -70,6 +117,20 @@ def create(self, extract_item: TaskItem) -> TaskItem:

@api(version="2.6")
def run(self, task_item: TaskItem) -> bytes:
"""
Runs the specified extract refresh task.

REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_jobs_tasks_and_schedules.htm#run_extract_refresh_task

Parameters
----------
task_item : TaskItem
The task to run.

Returns
-------
bytes
"""
if not task_item.id:
error = "Task item missing ID."
raise MissingRequiredFieldError(error)
Expand All @@ -86,6 +147,23 @@ def run(self, task_item: TaskItem) -> bytes:
# Delete 1 task by id
@api(version="3.6")
def delete(self, task_id: str, task_type: str = TaskItem.Type.ExtractRefresh) -> None:
"""
Deletes the specified extract refresh task on Tableau Server or Tableau Cloud.

REST API: https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#delete_extract_refresh_task

Parameters
----------
task_id : str
The ID of the task to delete.

task_type : str, default TaskItem.Type.ExtractRefresh
The type of task to query. See TaskItem.Type for possible values.

Returns
-------
None
"""
if task_type == TaskItem.Type.DataAcceleration:
self.parent_srv.assert_at_least_version("3.8", "Data Acceleration Tasks")

Expand Down
Loading