Skip to content

Commit fed7644

Browse files
author
Martin Peters
committed
Added tasks sections to api-ref.md
1 parent a2126f2 commit fed7644

File tree

1 file changed

+209
-0
lines changed

1 file changed

+209
-0
lines changed

docs/api-ref.md

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,6 +2709,215 @@ The `SubscriptionItem`. See [SubscriptionItem class](#subscriptionitem-class)
27092709
<br>
27102710
<br>
27112711

2712+
---
2713+
2714+
## Tasks
2715+
2716+
Using the TSC library, you can get information about all the tasks on a site and you can remove tasks. To create new tasks see [Schedules](#schedules).
2717+
2718+
The task resources for Tableau Server are defined in the `TaskItem` class. The class corresponds to the task resources you can access using the Tableau Server REST API. The task methods are based upon the endpoints for tasks in the REST API and operate on the `TaskItem` class.
2719+
2720+
### TaskItem class
2721+
2722+
```py
2723+
TaskItem(id, task_type, priority, consecutive_failed_count=0, schedule_id=None, target=None)
2724+
```
2725+
2726+
**Attributes**
2727+
2728+
Name | Description
2729+
:--- | :---
2730+
`consecutive_failed_count` | The number of failed consecutive executions.
2731+
`id` | The id of the task on the site.
2732+
`priority` | The priority of the task on the server.
2733+
`schedule_id` | The id of the schedule on the site.
2734+
`target` | An object, `datasource` or `workbook` which is associated to the task. Source file: models/target.py
2735+
`task_type` | Type of extract task - full or incremental refresh.
2736+
2737+
2738+
**Example**
2739+
2740+
```py
2741+
# import tableauserverclient as TSC
2742+
# server = TSC.Server('server')
2743+
2744+
task = server.tasks.get_by_id('9f9e9d9c-8b8a-8f8e-7d7c-7b7a6f6d6e6d')
2745+
print(task)
2746+
2747+
```
2748+
2749+
Source file: models/task_item.py
2750+
2751+
<br>
2752+
<br>
2753+
2754+
2755+
### Tasks methods
2756+
2757+
The Tableau Server Client provides several methods for interacting with task resources, or endpoints. These methods correspond to endpoints in the Tableau Server REST API.
2758+
2759+
Source file: server/endpoint/tasks_endpoint.py
2760+
<br>
2761+
<br>
2762+
2763+
#### tasks.get
2764+
2765+
```py
2766+
tasks.get(req_options=None)
2767+
```
2768+
2769+
Returns information about the tasks on the specified site.
2770+
2771+
REST API: [Get Extract Refresh Tasks on Site](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#get_extract_refresh_tasks){:target="_blank"}
2772+
2773+
2774+
**Parameters**
2775+
2776+
Name | Description
2777+
:--- | : ---
2778+
`req_option` | (Optional) You can pass the method a request object that contains additional parameters to filter the request.
2779+
2780+
2781+
**Returns**
2782+
2783+
Returns a list of `TaskItem` objects and a `PaginationItem` object. Use these values to iterate through the results.
2784+
2785+
2786+
**Example**
2787+
2788+
2789+
```py
2790+
import tableauserverclient as TSC
2791+
tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD')
2792+
server = TSC.Server('https://SERVERURL')
2793+
2794+
with server.auth.sign_in(tableau_auth):
2795+
all_tasks, pagination_item = server.tasks.get()
2796+
print("\nThere are {} tasks on site: ".format(pagination_item.total_available))
2797+
print([task.id for task in all_tasks])
2798+
```
2799+
2800+
<br>
2801+
<br>
2802+
2803+
#### tasks.get_by_id
2804+
2805+
2806+
```py
2807+
tasks.get_by_id(task_id)
2808+
```
2809+
2810+
Returns information about the specified task.
2811+
2812+
REST API: [Query Extract Refresh Task On Site](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#get_extract_refresh_task){:target="_blank"}
2813+
2814+
2815+
**Parameters**
2816+
2817+
Name | Description
2818+
:--- | : ---
2819+
`task_id` | The `task_id` specifies the task to query.
2820+
2821+
2822+
**Exceptions**
2823+
2824+
Error | Description
2825+
:--- | : ---
2826+
`Task ID undefined.` | Raises an exception if a valid `task_id` is not provided.
2827+
2828+
2829+
**Returns**
2830+
2831+
The `TaskItem`. See [TaskItem class](#taskitem-class)
2832+
2833+
2834+
**Example**
2835+
2836+
```py
2837+
task1 = server.tasks.get_by_id('9f9e9d9c-8b8a-8f8e-7d7c-7b7a6f6d6e6d')
2838+
print(task1.task_type)
2839+
2840+
```
2841+
2842+
<br>
2843+
<br>
2844+
2845+
#### tasks.run
2846+
2847+
2848+
```py
2849+
tasks.run(task_item)
2850+
```
2851+
2852+
Runs the specified extract refresh task.
2853+
2854+
To run a extract refresh task you need to first lookup the task `task_item` (`TaskItem` class).
2855+
2856+
REST API: [Run Extract Refresh Task](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref.htm#run_extract_refresh_task){:target="_blank"}
2857+
2858+
2859+
**Parameters**
2860+
2861+
Name | Description
2862+
:--- | : ---
2863+
`task_item` | You can pass the method a task object.
2864+
2865+
2866+
**Returns**
2867+
2868+
Returns the REST API response.
2869+
2870+
**Example**
2871+
2872+
```py
2873+
# import tableauserverclient as TSC
2874+
# server = TSC.Server('server')
2875+
# login, etc.
2876+
2877+
task = server.tasks.get_by_id('9f9e9d9c-8b8a-8f8e-7d7c-7b7a6f6d6e6d')
2878+
server.tasks.run(task)
2879+
2880+
```
2881+
2882+
<br>
2883+
<br>
2884+
2885+
#### tasks.delete
2886+
2887+
2888+
```py
2889+
tasks.delete(task_id)
2890+
```
2891+
2892+
Deletes an extract refresh task.
2893+
2894+
REST API: [Run Extract Refresh Task](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_jobstasksschedules.htm#delete_workbook){:target="_blank"}
2895+
2896+
**Parameters**
2897+
2898+
Name | Description
2899+
:--- | : ---
2900+
`task_id` | The `task_id` specifies the task to delete.
2901+
2902+
2903+
**Exceptions**
2904+
2905+
Error | Description
2906+
:--- | : ---
2907+
`Task ID undefined.` | Raises an exception if a valid `task_id` is not provided.
2908+
2909+
2910+
**Example**
2911+
2912+
```py
2913+
server.tasks.delete('9f9e9d9c-8b8a-8f8e-7d7c-7b7a6f6d6e6d')
2914+
2915+
```
2916+
2917+
<br>
2918+
<br>
2919+
2920+
27122921
---
27132922

27142923
## Users

0 commit comments

Comments
 (0)