8000 Merge pull request #525 from martinbpeters/gh-pages-tasks · shiv-io/server-client-python@49fe7db · GitHub
[go: up one dir, main page]

Skip to content

Commit 49fe7db

Browse files
authored
Merge pull request tableau#525 from martinbpeters/gh-pages-tasks
Tasks Documentation
2 parents 6ace934 + fed7644 commit 49fe7db

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
@@ -2883,6 +2883,215 @@ The `SubscriptionItem`. See [SubscriptionItem class](#subscriptionitem-class)
28832883
<br>
28842884
<br>
28852885

2886+
---
2887+
2888+
## Tasks
2889+
2890+
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).
2891+
2892+
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.
2893+
2894+
### TaskItem class
2895+
2896+
```py
2897+
TaskItem(id, task_type, priority, consecutive_failed_count=0, schedule_id=None, target=None)
2898+
```
2899+
2900+
**Attributes**
2901+
2902+
Name | Description
2903+
:--- | :---
2904+
`consecutive_failed_count` | The number of failed consecutive executions.
2905+
`id` | The id of the task on the site.
2906+
`priority` | The priority of the task on the server.
2907+
`schedule_id` | The id of the schedule on the site.
2908+
`target` | An object, `datasource` or `workbook` which is associated to the task. Source file: models/target.py
2909+
`task_type` | Type of extract task - full or incremental refresh.
2910+
2911+
2912+
**Example**
2913+
2914+
```py
2915+
# import tableauserverclient as TSC
2916+
# server = TSC.Server('server')
2917+
2918+
task = server.tasks.get_by_id('9f9e9d9c-8b8a-8f8e-7d7c-7b7a6f6d6e6d')
2919+
print(task)
2920+
2921+
```
2922+
2923+
Source file: models/task_item.py
2924+
2925+
<br>
2926+
<br>
2927+
2928+
2929+
### Tasks methods
2930+
2931+
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.
2932+
2933+
Source file: server/endpoint/tasks_endpoint.py
2934+
<br>
2935+
<br>
2936+
2937+
#### tasks.get
2938+
2939+
```py
2940+
tasks.get(req_options=None)
2941+
```
2942+
2943+
Returns information about the tasks on the specified site.
2944+
2945+
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"}
2946+
2947+
2948+
**Parameters**
2949+
2950+
Name | Description
2951+
:--- | : ---
2952+
`req_option` | (Optional) You can pass the method a request object that contains additional parameters to filter the request.
2953+
2954+
2955+
**Returns**
2956+
2957+
Returns a list of `TaskItem` objects and a `PaginationItem` object. Use these values to iterate through the results.
2958+
2959+
2960+
**Example**
2961+
2962+
2963+
```py
2964+
import tableauserverclient as TSC
2965+
tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD')
2966+
server = TSC.Server('https://SERVERURL')
2967+
2968+
with server.auth.sign_in(tableau_auth):
2969+
all_tasks, pagination_item = server.tasks.get()
2970+
print("\nThere are {} tasks on site: ".format(pagination_item.total_available))
2971+
print([task.id for task in all_tasks])
2972+
```
2973+
2974+
<br>
2975+
<br>
2976+
2977+
#### tasks.get_by_id
2978+
2979+
2980+
```py
2981+
tasks.get_by_id(task_id)
2982+
```
2983+
2984+
Returns information about the specified task.
2985+
2986+
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"}
2987+
2988+
2989+
**Parameters**
2990+
2991+
Name | Description
2992+
:--- | : ---
2993+
`task_id` | The `task_id` specifies the task to query.
2994+
2995+
2996+
**Exceptions**
2997+
2998+
Error | Description
2999+
:--- | : ---
3000+
`Task ID undefined.` | Raises an exception if a valid `task_id` is not provided.
3001+
3002+
3003+
**Returns**
3004+
3005+
The `TaskItem`. See [TaskItem class](#taskitem-class)
3006+
3007+
3008+
**Example**
3009+
3010+
```py
3011+
task1 = server.tasks.get_by_id('9f9e9d9c-8b8a-8f8e-7d7c-7b7a6f6d6e6d')
3012+
print(task1.task_type)
3013+
3014+
```
3015+
3016+
<br>
3017+
<br>
3018+
3019+
#### tasks.run
3020+
3021+
3022+
```py
3023+
tasks.run(task_item)
3024+
```
3025+
3026+
Runs the specified extract refresh task.
3027+
3028+
To run a extract refresh task you need to first lookup the task `task_item` (`TaskItem` class).
3029+
3030+
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"}
3031+
3032+
3033+
**Parameters**
3034+
3035+
Name | Description
3036+
:--- | : ---
3037+
`task_item` | You can pass the method a task object.
3038+
3039+
3040+
**Returns**
3041+
3042+
Returns the REST API response.
3043+
3044+
**Example**
3045+
3046+
```py
3047+
# import tableauserverclient as TSC
3048+
# server = TSC.Server('server')
3049+
# login, etc.
3050+
3051+
task = server.tasks.get_by_id('9f9e9d9c-8b8a-8f8e-7d7c-7b7a6f6d6e6d')
3052+
server.tasks.run(task)
3053+
3054+
```
3055+
3056+
<br>
3057+
<br>
3058+
3059+
#### tasks.delete
3060+
3061+
3062+
```py
3063+
tasks.delete(task_id)
3064+
```
3065+
3066+
Deletes an extract refresh task.
3067+
3068+
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"}
3069+
3070+
**Parameters**
3071+
3072+
Name | Description
3073+
:--- | : ---
3074+
`task_id` | The `task_id` specifies the task to delete.
3075+
3076+
3077+
**Exceptions**
3078+
3079+
Error | Description
3080+
:--- | : ---
3081+
`Task ID undefined.` | Raises an exception if a valid `task_id` is not provided.
3082+
3083+
3084+
**Example**
3085+
3086+
```py
3087+
server.tasks.delete('9f9e9d9c-8b8a-8f8e-7d7c-7b7a6f6d6e6d')
3088+
3089+
```
3090+
3091+
<br>
3092+
<br>
3093+
3094+
28863095
---
28873096

28883097
## Users

0 commit comments

Comments
 (0)
0