Skip to content

Commit 4e21781

Browse files
jacalatajorwoods
andcommitted
docs: document flow_runs endpoint (#1757)
Co-authored-by: Jordan Woods <13803242+jorwoods@users.noreply.github.com>
1 parent e8af81b commit 4e21781

1 file changed

Lines changed: 235 additions & 0 deletions

File tree

docs/api-ref.md

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,6 +3158,241 @@ for flow in matching_flows:
31583158

31593159
---
31603160

3161+
## Flow Runs
3162+
3163+
Using the TSC library, you can query flow runs on a site, get details about a specific flow run, cancel a running flow, or wait for a flow run to complete. Flow runs are created when a flow is triggered to run, either manually or on a schedule.
3164+
3165+
The flow run resources for Tableau Server are defined in the `FlowRunItem` class. The class corresponds to the flow run resources you can access using the Tableau Server REST API.
3166+
3167+
<br>
3168+
3169+
### FlowRunItem class
3170+
3171+
The `FlowRunItem` represents the result of a flow run on Tableau Server. Instances of this class are returned by the flow run methods; you do not create them directly.
3172+
3173+
**Attributes**
3174+
3175+
Name | Description
3176+
:--- | :---
3177+
`id` | The identifier for the flow run.
3178+
`flow_id` | The identifier of the flow that was run.
3179+
`status` | The current status of the flow run. Possible values include `Success`, `Failed`, and `Cancelled`.
3180+
`started_at` | The date and time when the flow run started.
3181+
`completed_at` | The date and time when the flow run completed. Is `None` if the run is still in progress.
3182+
`progress` | The progress percentage of the flow run.
3183+
`background_job_id` | The identifier of the background job associated with the flow run.
3184+
3185+
Source file: models/flow_run_item.py
3186+
3187+
<br>
3188+
<br>
3189+
3190+
### Flow Runs methods
3191+
3192+
The Tableau Server Client provides several methods for interacting with flow run resources. These methods correspond to endpoints in the Tableau Server REST API.
3193+
3194+
Source file: server/endpoint/flow_runs_endpoint.py
3195+
3196+
<br>
3197+
<br>
3198+
3199+
#### flow_runs.get
3200+
3201+
```py
3202+
flow_runs.get(req_options=None)
3203+
```
3204+
3205+
Returns all flow runs on the site.
3206+
3207+
REST API: [Get Flow Runs](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_flow.htm#get_flow_runs){:target="_blank"}
3208+
3209+
**Parameters**
3210+
3211+
Name | Description
3212+
:--- | :---
3213+
`req_options` | (Optional) You can pass the method a request object that contains additional parameters to filter the request.
3214+
3215+
**Returns**
3216+
3217+
Returns a list of `FlowRunItem` objects. Be aware that `flowruns.get` does *NOT* return a `PaginationItem`.
3218+
3219+
**Version**
3220+
3221+
Version 3.10 and later. See [REST API versions](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_concepts_versions.htm).
3222+
3223+
**Example**
3224+
3225+
```py
3226+
import tableauserverclient as TSC
3227+
tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD')
3228+
server = TSC.Server('https://SERVERURL')
3229+
3230+
with server.auth.sign_in(tableau_auth):
3231+
all_runs, pagination_item = server.flow_runs.get()
3232+
print("\nThere are {} flow runs on site.".format(pagination_item.total_available))
3233+
for run in all_runs:
3234+
print(run.id, run.status)
3235+
```
3236+
3237+
<br>
3238+
<br>
3239+
3240+
#### flow_runs.get_by_id
3241+
3242+
```py
3243+
flow_runs.get_by_id(flow_run_id)
3244+
```
3245+
3246+
Returns the specified flow run item.
3247+
3248+
REST API: [Get Flow Run](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_flow.htm#get_flow_run){:target="_blank"}
3249+
3250+
**Parameters**
3251+
3252+
Name | Description
3253+
:--- | :---
3254+
`flow_run_id` | The identifier (`id`) for the `FlowRunItem` to query.
3255+
3256+
**Exceptions**
3257+
3258+
Error | Description
3259+
:--- | :---
3260+
`Flow ID undefined` | Raises an exception if a valid `flow_run_id` is not provided.
3261+
3262+
**Returns**
3263+
3264+
Returns a `FlowRunItem`.
3265+
3266+
**Version**
3267+
3268+
Version 3.10 and later. See [REST API versions](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_concepts_versions.htm).
3269+
3270+
**Example**
3271+
3272+
```py
3273+
flow_run = server.flow_runs.get_by_id('1a2a3b4b-5c6c-7d8d-9e0e-1f2f3a4a5b6b')
3274+
print(flow_run.status, flow_run.progress)
3275+
```
3276+
3277+
<br>
3278+
<br>
3279+
3280+
#### flow_runs.cancel
3281+
3282+
```py
3283+
flow_runs.cancel(flow_run_id)
3284+
```
3285+
3286+
Cancels the specified flow run.
3287+
3288+
REST API: [Cancel Flow Run](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_flow.htm#cancel_flow_run){:target="_blank"}
3289+
3290+
**Parameters**
3291+
3292+
Name | Description
3293+
:--- | :---
3294+
`flow_run_id` | The identifier (`id`) for the `FlowRunItem` to cancel. Can be the id string or a `FlowRunItem` object.
3295+
3296+
**Exceptions**
3297+
3298+
Error | Description
3299+
:--- | :---
3300+
`Flow ID undefined` | Raises an exception if a valid `flow_run_id` is not provided.
3301+
3302+
**Version**
3303+
3304+
Version 3.10 and later. See [REST API versions](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_concepts_versions.htm).
3305+
3306+
**Example**
3307+
3308+
```py
3309+
flow_run = server.flow_runs.get_by_id('1a2a3b4b-5c6c-7d8d-9e0e-1f2f3a4a5b6b')
3310+
server.flow_runs.cancel(flow_run.id)
3311+
```
3312+
3313+
<br>
3314+
<br>
3315+
3316+
#### flow_runs.wait_for_job
3317+
3318+
```py
3319+
flow_runs.wait_for_job(flow_run_id, *, timeout=None)
3320+
```
3321+
3322+
Waits for the specified flow run to complete and returns the finished `FlowRunItem`. This method polls the server repeatedly using exponential backoff until the run completes, then raises an exception if it failed or was cancelled.
3323+
3324+
**Parameters**
3325+
3326+
Name | Description
3327+
:--- | :---
3328+
`flow_run_id` | The identifier (`id`) for the flow run to wait for. Can be the id string or a `FlowRunItem` object.
3329+
`timeout` | (Optional) The maximum number of seconds to wait before raising a timeout error. If not specified, waits indefinitely.
3330+
3331+
**Exceptions**
3332+
3333+
Error | Description
3334+
:--- | :---
3335+
`FlowRunFailedException` | Raised if the flow run completes with a `Failed` status.
3336+
`FlowRunCancelledException` | Raised if the flow run completes with a `Cancelled` status.
3337+
3338+
**Returns**
3339+
3340+
Returns the completed `FlowRunItem` if the run succeeded.
3341+
3342+
**Version**
3343+
3344+
Version 3.10 and later. See [REST API versions](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_concepts_versions.htm).
3345+
3346+
**Example**
3347+
3348+
```py
3349+
# Trigger a flow run and wait for it to finish
3350+
flow = server.flows.get_by_id('1a2a3b4b-5c6c-7d8d-9e0e-1f2f3a4a5b6b')
3351+
job = server.flows.refresh(flow)
3352+
3353+
# Wait for the resulting flow run to complete
3354+
flow_run = server.flow_runs.wait_for_job(job.id, timeout=300)
3355+
print("Flow run completed with status: {}".format(flow_run.status))
3356+
```
3357+
3358+
<br>
3359+
<br>
3360+
3361+
#### flow_runs.filter
3362+
3363+
```py
3364+
flow_runs.filter(**kwargs)
3365+
```
3366+
3367+
Returns a list of flow runs that match the specified filters. Fields and operators are passed as keyword arguments in the form `field_name=value` or `field_name__operator=value`.
3368+
3369+
**Supported fields and operators**
3370+
3371+
Field | Operators
3372+
:--- | :---
3373+
`complete_at` | `eq`, `gt`, `gte`, `lt`, `lte`
3374+
`flow_id` | `eq`, `in`
3375+
`progress` | `eq`, `gt`, `gte`, `lt`, `lte`
3376+
`started_at` | `eq`, `gt`, `gte`, `lt`, `lte`
3377+
`user_id` | `eq`, `in`
3378+
3379+
**Returns**
3380+
3381+
Returns a `QuerySet` of `FlowRunItem` objects.
3382+
3383+
**Example**
3384+
3385+
```py
3386+
flow = server.flows.get_by_id('1a2a3b4b-5c6c-7d8d-9e0e-1f2f3a4a5b6b')
3387+
recent_runs = server.flow_runs.filter(flow_id=flow.id)
3388+
for run in recent_runs:
3389+
print(run.id, run.status)
3390+
```
3391+
3392+
<br>
3393+
3394+
---
3395+
31613396
## Groups
31623397

31633398
Using the TSC library, you can get information about all the groups on a site, you can add or remove groups, or add or remove users in a group.

0 commit comments

Comments
 (0)