-
Notifications
You must be signed in to change notification settings - Fork 436
Add FlowRun Item and Endpoints. #884
8000
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
12f9f9e
Add tests for fetching flow runs
jorwoods e1f2fb6
Implement basics of FlowRuns
jorwoods dbc6888
Add tests for cancel flow run
jorwoods 1210e19
Make FlowRuns a Queryset endpoint for easier filtering
ac140d1
Add test for flow refresh endpoint
6fc3466
Align to naming conventions
54a4ac1
Apply name change consistently
6280429
Change flowrun_id into flow_run_id
83ef17b
Add wait_for_job to FlowRun
e9b9703
Tag wait_for_job with version number
jorwoods 6627762
Rewrite flow_run to use ExponentialBackoffTimer
jorwoods a57cb14
Test flow run wait with backoff
jorwoods 1e9c863
Remove 3.5 from test matrix
jorwoods 28ae64d
Standardize spelling of cancelled
jorwoods File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
FlowItem, | ||
WebhookItem, | ||
PersonalAccessTokenAuth, | ||
FlowRunItem | ||
) | ||
from .server import ( | ||
RequestOptions, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import xml.etree.ElementTree as ET | ||
from ..datetime_helpers import parse_datetime | ||
import itertools | ||
|
||
|
||
class FlowRunItem(object): | ||
def __init__(self) -> None: | ||
self._id=None | ||
self._flow_id=None | ||
self._status=None | ||
self._started_at=None | ||
self._completed_at=None | ||
self._progress=None | ||
self._background_job_id=None | ||
|
||
|
||
@property | ||
def id(self): | ||
return self._id | ||
|
||
|
||
@property | ||
def flow_id(self): | ||
return self._flow_id | ||
|
||
|
||
@property | ||
def status(self): | ||
return self._status | ||
|
||
|
||
@property | ||
def started_at(self): | ||
return self._started_at | ||
|
||
|
||
@property | ||
def completed_at(self): | ||
return self._completed_at | ||
|
||
|
||
@property | ||
def progress(self): | ||
return self._progress | ||
|
||
|
||
@property | ||
def background_job_id(self): | ||
return self._background_job_id | ||
|
||
|
||
def _set_values( | ||
self, | ||
id, | ||
flow_id, | ||
status, | ||
started_at, | ||
completed_at, | ||
progress, | ||
background_job_id, | ||
): | ||
if id is not None: | ||
self._id = id | ||
if flow_id is not None: | ||
self._flow_id = flow_id | ||
if status is not None: | ||
self._status = status | ||
if started_at is not None: | ||
self._started_at = started_at | ||
if completed_at is not None: | ||
self._completed_at = completed_at | ||
if progress is not None: | ||
self._progress = progress | ||
if background_job_id is not None: | ||
self._background_job_id = background_job_id | ||
|
||
|
||
@classmethod | ||
def from_response(cls, resp, ns): | ||
all_flowrun_items = list() | ||
parsed_response = ET.fromstring(resp) | ||
all_flowrun_xml = itertools.chain( | ||
parsed_response.findall(".//t:flowRun[@id]", namespaces=ns), | ||
parsed_response.findall(".//t:flowRuns[@id]", namespaces=ns) | ||
) | ||
|
||
for flowrun_xml in all_flowrun_xml: | ||
parsed = cls._parse_element(flowrun_xml, ns) | ||
flowrun_item = cls() | ||
flowrun_item._set_values(**parsed) | ||
all_flowrun_items.append(flowrun_item) | ||
return all_flowrun_items | ||
|
||
|
||
@staticmethod | ||
def _parse_element(flowrun_xml, ns): | ||
result = {} | ||
result['id'] = flowrun_xml.get("id", None) | ||
result['flow_id'] = flowrun_xml.get("flowId", None) | ||
result['status'] = flowrun_xml.get("status", None) | ||
result['started_at'] = parse_datetime(flowrun_xml.get("startedAt", None)) | ||
result['completed_at'] = parse_datetime(flowrun_xml.get("completedAt", None)) | ||
result['progress'] = flowrun_xml.get("progress", None) | ||
result['background_job_id'] = flowrun_xml.get("backgroundJobId", None) | ||
|
||
return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
ColumnItem, | ||
FlowItem, | ||
WebhookItem, | ||
FlowRunItem | ||
) | ||
from .endpoint import ( | ||
Auth, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from .endpoint import Endpoint, QuerysetEndpoint, api | ||
from .exceptions import FlowRunFailedException, FlowRunCancelledException | ||
from .. import FlowRunItem, PaginationItem | ||
from ...exponential_backoff import ExponentialBackoffTimer | ||
|
||
import logging | ||
|
||
logger = logging.getLogger("tableau.endpoint.flowruns") | ||
|
||
|
||
class FlowRuns(QuerysetEndpoint): | ||
def __init__(self, parent_srv): | ||
super(FlowRuns, self).__init__(parent_srv) | ||
|
||
@property | ||
def baseurl(self): | ||
return "{0}/sites/{1}/flows/runs".format(self.parent_srv.baseurl, self.parent_srv.site_id) | ||
|
||
# Get all flows | ||
@api(version="3.10") | ||
def get(self, req_options=None): | ||
logger.info("Querying all flow runs on site") | ||
url = self.baseurl | ||
server_response = self.get_request(url, req_options) | ||
pagination_item = PaginationItem.from_response(server_response.content, self.parent_srv.namespace) | ||
all_flow_run_items = FlowRunItem.from_response(server_response.content, self.parent_srv.namespace) | ||
return all_flow_run_items, pagination_item | ||
|
||
# Get 1 flow by id | ||
@api(version="3.10") | ||
def get_by_id(self, flow_run_id): | ||
if not flow_run_id: | ||
error = "Flow ID undefined." | ||
raise ValueError(error) | ||
logger.info("Querying single flow (ID: {0})".format(flow_run_id)) | ||
url = "{0}/{1}".format(self.baseurl, flow_run_id) | ||
server_response = self.get_request(url) | ||
return FlowRunItem.from_response(server_response.content, self.parent_srv.namespace)[0] | ||
|
||
|
||
# Cancel 1 flow run by id | ||
@api(version="3.10") | ||
def cancel(self, flow_run_id): | ||
if not flow_run_id: | ||
error = "Flow ID undefined." | ||
raise ValueError(error) | ||
id_ = getattr(flow_run_id, 'id', flow_run_id) | ||
url = "{0}/{1}".format(self.baseurl, id_) | ||
self.put_request(url) | ||
logger.info("Deleted single flow (ID: {0})".format(id_)) | ||
|
||
|
||
@api(version="3.10") | ||
def wait_for_job(self, flow_run_id, *, timeout=None): | ||
if isinstance(flow_run_id, FlowRunItem): | ||
flow_run_id = flow_run_id.id | ||
assert isinstance(flow_run_id, str) | ||
logger.debug(f"Waiting for flow run {flow_run_id}") | ||
|
||
backoffTimer = ExponentialBackoffTimer(timeout=timeout) | ||
flow_run = self.get_by_id(flow_run_id) | ||
while flow_run.completed_at is None: | ||
backoffTimer.sleep() | ||
flow_run = self.get_by_id(flow_run_id) | ||
logger.debug(f"\tFlowRun {flow_run_id} progress={flow_run.progress}") | ||
|
||
logger.info("FlowRun {} Completed: Status: {}".format(flow_run_id, flow_run.status)) | ||
|
||
if flow_run.status == "Success": | ||
return flow_run | ||
elif flow_run.status == "Failed": | ||
raise FlowRunFailedException(flow_run) | ||
elif flow_run.status == "Cancelled": | ||
raise FlowRunCancelledException(flow_run) | ||
else: | ||
raise AssertionError("Unexpected status in flow_run", flow_run) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-3.5.xsd"> | ||
<job id="d1b2ccd0-6dfa-444a-aee4-723dbd6b7c9d" | ||
mode="Asynchronous" | ||
type="RunFlow" | ||
createdAt="2018-05-22T13:00:29Z"> | ||
<runFlowJobType flowRunId="e0c3067f-2333-4eee-8028-e0a56ca496f6"> | ||
<flow id="92967d2d-c7e2-46d0-8847-4802df58f484" name="FlowOne"/> | ||
</runFlowJobType> | ||
</job> | ||
</tsResponse> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled diff
BF4E
erently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-3.10.xsd"> | ||
<pagination pageNumber="1" pageSize="100" totalAvailable="2"/> | ||
<flowRuns> | ||
<flowRuns id="cc2e652d-4a9b-4476-8c93-b238c45db968" | ||
flowId="587daa37-b84d-4400-a9a2-aa90e0be7837" | ||
status="Success" | ||
startedAt="2021-02-11T01:42:55Z" | ||
completedAt="2021-02-11T01:57:38Z" | ||
progress="100" | ||
backgroundJobId="aa23f4ac-906f-11e9-86fb-3f0f71412e77"/> | ||
<flowRuns id="a3104526-c0c6-4ea5-8362-e03fc7cbd7ee" | ||
flowId="5c36be69-eb30-461b-b66e-3e2a8e27cc35" | ||
status="Failed" | ||
startedAt="2021-02-13T04:05:30Z" | ||
completedAt="2021-02-13T04:05:35Z" | ||
progress="100" | ||
backgroundJobId="1ad21a9d-2530-4fbf-9064-efd3c736e023"/> | ||
</flowRuns> | ||
</tsResponse> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-3.10.xsd"> | ||
<flowRun id="cc2e652d-4a9b-4476-8c93-b238c45db968" | ||
flowId="587daa37-b84d-4400-a9a2-aa90e0be7837" | ||
status="Success" | ||
startedAt="2021-02-11T01:42:55Z" | ||
completedAt="2021-02-11T01:57:38Z" | ||
progress="100" | ||
backgroundJobId="1ad21a9d-2530-4fbf-9064-efd3c736e023"> | ||
</flowRun> | ||
</tsResponse> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.