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

 ##########
 File path: airflow/providers/salesforce/sensors/tableau_job_status.py
 ##########
 @@ -0,0 +1,63 @@
+# 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 typing import Optional
+
+from airflow.providers.salesforce.hooks.tableau import TableauHook
+from airflow.sensors.base_sensor_operator import BaseSensorOperator
+from airflow.utils.decorators import apply_defaults
+
+
+class TableauJobStatusSensor(BaseSensorOperator):
+    """
+    Watches the status of a Tableau Server Job.
+
+    .. seealso:: 
https://tableau.github.io/server-client-python/docs/api-ref#jobs
+
+    :param job_id: The job to watch.
+    :type job_id: str
+    :param site_id: The id of the site where the workbook belongs to.
+    :type site_id: Optional[str]
+    :param tableau_conn_id: The Tableau Connection id containing the 
credentials
+        to authenticate to the Tableau Server.
+    :type tableau_conn_id: str
+    """
+
+    template_fields = ('job_id',)
+
+    @apply_defaults
+    def __init__(self,
+                 job_id: str,
+                 *args,
+                 site_id: Optional[str] = None,
+                 tableau_conn_id: str = 'tableau_default',
+                 **kwargs):
+        super().__init__(*args, **kwargs)
+        self.tableau_conn_id = tableau_conn_id
+        self.job_id = job_id
+        self.site_id = site_id
+
+    def poke(self, context):
+        """
+        Pokes for a job to successfully finish.
+
+        :param context: The task context during execution.
+        :type context: dict
+        :return: True if it succeeded and False if not.
+        :rtype: bool
+        """
+        with TableauHook(self.site_id, self.tableau_conn_id) as tableau_hook:
+            return tableau_hook.server.jobs.get(self.job_id).finish_code != -1
 
 Review comment:
   > Can we make a constant out of the -1? To avoid magic numbers in the code.
   
   Good Point. I will do that.
   
   > What are the options in terms of return codes here? Can we check if the 
notebook successfully refreshed, or maybe if it threw an error while refreshing?
   
   Yes I need to check that! Thanks.
   _The finishCode indicates the status of the job: 0 for success, 1 for error, 
or 2 for cancelled._ - REST API docs (not python client docs)
   That is really weird, because I got a `-1` for a failed Job. I definitly 
need to check that again!
   

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to