8000 [Tasks] Translate task type from server to TSC enum by shinchris · Pull Request #796 · tableau/server-client-python · GitHub
[go: up one dir, main page]

Skip to content

[Tasks] Translate task type from server to TSC enum #796

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 3 commits into from
Feb 16, 2021
Merged
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
15 changes: 14 additions & 1 deletion tableauserverclient/models/task_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class Type:
ExtractRefresh = "extractRefresh"
DataAcceleration = "dataAcceleration"

# This mapping is used to convert task type returned from server
_TASK_TYPE_MAPPING = {'RefreshExtractTask': Type.ExtractRefresh,
'MaterializeViewsTask': Type.DataAcceleration}

def __init__(self, id_, task_type, priority, consecutive_failed_count=0, schedule_id=None,
schedule_item=None, last_run_at=None, target=None):
self.id = id_
Expand Down Expand Up @@ -58,9 +62,18 @@ def _parse_element(cls, element, ns):
if last_run_at_element is not None:
last_run_at = parse_datetime(last_run_at_element.text)

task_type = element.get('type', None)
# Server response has different names for task types
task_type = cls._translate_task_type(element.get('type', None))

priority = int(element.get('priority', -1))
consecutive_failed_count = int(element.get('consecutiveFailedCount', 0))
id_ = element.get('id', None)
return cls(id_, task_type, priority, consecutive_failed_count, schedule_item.id,
schedule_item, last_run_at, target)

@staticmethod
def _translate_task_type(task_type):
if task_type in TaskItem._TASK_TYPE_MAPPING:
return TaskItem._TASK_TYPE_MAPPING[task_type]
else:
return task_type
6 changes: 3 additions & 3 deletions test/assets/tasks_no_workbook_or_datasource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.6.xsd">
<tasks>
<task>
<extractRefresh id="f84901ac-72ad-4f9b-a87e-7a3500402ad6" priority="50" consecutiveFailedCount="0" type="REFRESH_EXTRACT">
<extractRefresh id="f84901ac-72ad-4f9b-a87e-7a3500402ad6" priority="50" consecutiveFailedCount="0" type="RefreshExtractTask">
<schedule id="b60b4efd-a6f7-4599-beb3-cb677e7abac1" name="Refresh daily [23:00 - 01:00, Pacific US]" state="Active" priority="50" createdAt="2016-02-11T01:42:55Z" updatedAt="2017-07-12T06:00:06Z" type="Extract" frequency="Daily" nextRunAt="2017-07-13T06:00:00Z" />
</extractRefresh>
</task>
<task>
<extractRefresh id="6e8255f1-142b-4e17-bd9a-9fe6736812a1" priority="50" consecutiveFailedCount="0" type="REFRESH_EXTRACT">
<extractRefresh id="6e8255f1-142b-4e17-bd9a-9fe6736812a1" priority="50" consecutiveFailedCount="0" type="RefreshExtractTask">
<schedule id="82974721-6831-4c78-875c-b7c2d5237bc2" name="Refresh daily [15:00 - 17:00, Pacific US]" state="Active" priority="50" createdAt="2016-02-11T01:39:39Z" updatedAt="2017-07-12T22:00:05Z" type="Extract" frequency="Daily" nextRunAt="2017-07-13T22:00:00Z" />
</extractRefresh>
</task>
<task>
<extractRefresh id="90cbc49a-b668-4355-9321-46f7fefd4197" priority="50" consecutiveFailedCount="0" type="REFRESH_EXTRACT">
<extractRefresh id="90cbc49a-b668-4355-9321-46f7fefd4197" priority="50" consecutiveFailedCount="0" type="RefreshExtractTask">
<schedule id="c39a5a41-ab5b-4661-90f6-78384916748c" name="Refresh daily [00:00 - 02:00, Pacific US]" state="Active" priority="50" createdAt="2016-02-11T01:33:51Z" updatedAt="2017-07-12T07:00:08Z" type="Extract" frequency="Daily" nextRunAt="2017-07-13T07:00:00Z" />
</extractRefresh>
</task>
Expand Down
2 changes: 1 addition & 1 deletion test/assets/tasks_with_dataacceleration_task.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<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.8.xsd">
<tasks>
<task>
<dataAcceleration id="2b217acb-194a-4291-ae90-7d5ec360395d" consecutiveFailedCount="0" type="DataAccelerationTask">
<dataAcceleration id="2b217acb-194a-4291-ae90-7d5ec360395d" consecutiveFailedCount="0" type="MaterializeViewsTask">
<schedule id="b22190b4-6ac2-4eed-9563-4afc03444413" name="Hourly4-Schedule" state="Active" priority="75" createdAt="2019-12-06T03:27:35Z" updatedAt="2019-12-09T20:30:59Z" type="DataAcceleration" frequency="Hourly" nextRunAt="2019-12-09T22:30:00Z">
<frequencyDetails start="02:30:00" end="23:00:00">
<intervals>
Expand Down
2 changes: 1 addition & 1 deletion test/assets/tasks_with_datasource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.6.xsd">
<tasks>
<task>
<extractRefresh id="f84901ac-72ad-4f9b-a87e-7a3500402ad6" priority="50" consecutiveFailedCount="0" type="REFRESH_EXTRACT">
<extractRefresh id="f84901ac-72ad-4f9b-a87e-7a3500402ad6" priority="50" consecutiveFailedCount="0" type="RefreshExtractTask">
<schedule id="b60b4efd-a6f7-4599-beb3-cb677e7abac1" name="Refresh daily [23:00 - 01:00, Pacific US]" state="Active" priority="50" createdAt="2016-02-11T01:42:55Z" updatedAt="2017-07-12T06:00:06Z" type="Extract" frequency="Daily" nextRunAt="2017-07-13T06:00:00Z" />
<datasource id="c7a9327e-1cda-4504-b026-ddb43b976d1d" />
</extractRefresh>
Expand Down
2 changes: 1 addition & 1 deletion test/assets/tasks_with_workbook.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.6.xsd">
<tasks>
<task>
<extractRefresh id="f84901ac-72ad-4f9b-a87e-7a3500402ad6" priority="50" consecutiveFailedCount="0" type="REFRESH_EXTRACT">
<extractRefresh id="f84901ac-72ad-4f9b-a87e-7a3500402ad6" priority="50" consecutiveFailedCount="0" type="RefreshExtractTask">
<schedule id="b60b4efd-a6f7-4599-beb3-cb677e7abac1" name="Refresh daily [23:00 - 01:00, Pacific US]" state="Active" priority="50" createdAt="2016-02-11T01:42:55Z" updatedAt="2017-07-12T06:00:06Z" type="Extract" frequency="Daily" nextRunAt="2017-07-13T06:00:00Z" />
<workbook id="c7a9327e-1cda-4504-b026-ddb43b976d1d" />
</extractRefresh>
Expand Down
6 changes: 3 additions & 3 deletions test/assets/tasks_with_workbook_and_datasource.xml
Original file line number Diff line number Diff line change EDBE
Expand Up @@ -4,19 +4,19 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api http://tableau.com/api/ts-api-2.6.xsd">
<tasks>
<task>
<extractRefresh id="f84901ac-72ad-4f9b-a87e-7a3500402ad6" priority="50" consecutiveFailedCount="0" type="REFRESH_EXTRACT">
<extractRefresh id="f84901ac-72ad-4f9b-a87e-7a3500402ad6" priority="50" consecutiveFailedCount="0" type="RefreshExtractTask">
<schedule id="b60b4efd-a6f7-4599-beb3-cb677e7abac1" name="Refresh daily [23:00 - 01:00, Pacific US]" state="Active" priority="50" createdAt="2016-02-11T01:42:55Z" updatedAt="2017-07-12T06:00:06Z" type="Extract" frequency="Daily" nextRunAt="2017-07-13T06:00:00Z" />
<workbook id="c7a9327e-1cda-4504-b026-ddb43b976d1d" />
</extractRefresh>
</task>
<task>
<extractRefresh id="6e8255f1-142b-4e17-bd9a-9fe6736812a1" priority="50" consecutiveFailedCount="0" type="REFRESH_EXTRACT">
<extractRefresh id="6e8255f1-142b-4e17-bd9a-9fe6736812a1" priority="50" consecutiveFailedCount="0" type="RefreshExtractTask">
<schedule id="82974721-6831-4c78-875c-b7c2d5237bc2" name="Refresh daily [15:00 - 17:00, Pacific US]" state="Active" priority="50" createdAt="2016-02-11T01:39:39Z" updatedAt="2017-07-12T22:00:05Z" type="Extract" frequency="Daily" nextRunAt="2017-07-13T22:00:00Z" />
<datasource id="61334430-fb0c-43af-a5a3-8db3323644b6" />
</extractRefresh>
</task>
<task>
<extractRefresh id="90cbc49a-b668-4355-9321-46f7fefd4197" priority="50" consecutiveFailedCount="0" type="REFRESH_EXTRACT">
<extractRefresh id="90cbc49a-b668-4355-9321-46f7fefd4197" priority="50" consecutiveFailedCount="0" type="RefreshExtractTask">
<schedule id="c39a5a41-ab5b-4661-90f6-78384916748c" name="Refresh daily [00:00 - 02:00, Pacific US]" state="Active" priority="50" createdAt="2016-02-11T01:33:51Z" updatedAt="2017-07-12T07:00:08Z" type="Extract" frequency="Daily" nextRunAt="2017-07-13T07:00:00Z" />
<workbook id="952663f4-1bb4-4fed-91f8-5967f48c533a" />
</extractRefresh>
Expand Down
2 changes: 2 additions & 0 deletions test/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def test_get_materializeviews_tasks(self):
self.assertEqual('b22190b4-6ac2-4eed-9563-4afc03444413', task.schedule_id)
self.assertEqual(parse_datetime('2019-12-09T22:30:00Z'), task.schedule_item.next_run_at)
self.assertEqual(parse_datetime('2019-12-09T20:45:04Z'), task.last_run_at)
self.assertEqual(TSC.TaskItem.Type.DataAcceleration, task.task_type)

def test_delete_data_acceleration(self):
with requests_mock.mock() as m:
Expand All @@ -124,6 +125,7 @@ def test_get_by_id(self):
self.assertEqual('c7a9327e-1cda-4504-b026-ddb43b976d1d', task.target.id)
self.assertEqual('workbook', task.target.type)
self.assertEqual('b60b4efd-a6f7-4599-beb3-cb677e7abac1', task.schedule_id)
self.assertEqual(TSC.TaskItem.Type.ExtractRefresh, task.task_type)

def test_run_now(self):
task_id = 'f84901ac-72ad-4f9b-a87e-7a3500402ad6'
Expand Down
0