You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/02/13 13:50:32 UTC

[GitHub] [airflow] eladkal commented on a change in pull request #7410: [AIRFLOW-6790] Add basic Tableau Integration

eladkal commented on a change in pull request #7410: [AIRFLOW-6790] Add basic Tableau Integration
URL: https://github.com/apache/airflow/pull/7410#discussion_r378870358
 
 

 ##########
 File path: airflow/providers/salesforce/operators/tableau_refresh_workbook.py
 ##########
 @@ -0,0 +1,74 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from airflow import AirflowException
+from airflow.models import BaseOperator
+from airflow.providers.salesforce.hooks.tableau import TableauHook
+from airflow.utils.decorators import apply_defaults
+
+
+class TableauRefreshWorkbookOperator(BaseOperator):
+    """
+    Refreshes a Tableau Workbook/Extract
+
+    :param workbook_name: The name of the workbook to refresh.
+    :type workbook_name: str
+    :param site_id: The id of the site where the workbook belongs to.
+    :type site_id: str
+    :param tableau_conn_id: The Tableau Connection id containing the credentials
+        to authenticate to the Tableau Server.
+    :type tableau_conn_id: str
+    """
+
+    @apply_defaults
+    def __init__(self,
+                 workbook_name,
+                 *args,
+                 site_id='',
+                 tableau_conn_id='tableau_default',
+                 **kwargs):
+        super().__init__(*args, **kwargs)
+        self.workbook_name = workbook_name
+        self.site_id = site_id
+        self.tableau_conn_id = tableau_conn_id
+
+    def execute(self, context):
+        """
+        Executes the Tableau Extract Refresh and pushes the job id to xcom.
+
+        :param context: The task context during execution.
+        :type context: dict
+        :return: the id of the job that executes the extract refresh
+        :rtype: str
+        """
+        with TableauHook(self.site_id, self.tableau_conn_id) as tableau_hook:
+            workbook = self._get_workbook_by_name(tableau_hook)
+
+            return self._refresh_workbook(tableau_hook, workbook.id)
+
+    def _get_workbook_by_name(self, tableau_hook):
+        for workbook in tableau_hook.get_all(resource_name='workbooks'):
+            if workbook.name == self.workbook_name:
+                self.log.info('Found matching workbook with id %s', workbook.id)
+                return workbook
+
+        raise AirflowException(f'Workbook {self.workbook_name} not found!')
+
+    def _refresh_workbook(self, tableau_hook, workbook_id):
+        job = tableau_hook.server.workbooks.refresh(workbook_id)
 
 Review comment:
   Does this support refreshing individual workbook report or the whole workbook ?
   Say I have:
   `https://url/#/site/site_name/views/Calls/Department`
   `https://url/#/site/site_name/views/Calls/Agents`
   if I pass `Calls` would it refresh both `Department` & `Agents` ?
   What if I pass `Calls/Agents` ?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services