marcosmarxm commented on a change in pull request #14492: URL: https://github.com/apache/airflow/pull/14492#discussion_r584370130
########## File path: airflow/providers/airbyte/hooks/airbyte.py ########## @@ -0,0 +1,92 @@ +# +# 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. +import time +from typing import Optional + +from airflow.exceptions import AirflowException +from airflow.providers.http.hooks.http import HttpHook + + +class AirbyteJobController: + """Airbyte job status""" + + RUNNING = "running" + SUCCEEDED = "succeeded" + CANCELLED = "canceled" + PENDING = "pending" + FAILED = "failed" + ERROR = "error" + + +class AirbyteHook(HttpHook, AirbyteJobController): + """Hook for Airbyte API""" + + def __init__(self, airbyte_conn_id: str) -> None: + super().__init__(http_conn_id=airbyte_conn_id) + + def wait_for_job(self, job_id: str, wait_time: int = 3, timeout: Optional[int] = None) -> None: Review comment: @turbaszek and @dstandish I created the **AirbyteSensor** class. At that moment I think it is working like **DataprocOperator**. I can send a parameter `asynchronous = True`. In this way, **AirbyteOperator** returns the `job_id` right after the job creation call. That way, the user can follow the job using AirbyteSensor. The DAG would look something: `op >> sensor`. For cases where performance and works slot aren't a problem, it's possible to use the `asynchronous = False` (default) parameter the operator will make calls to the `wait_for_job` function waiting for some result: error, canceled, completed. I worry a little about the async calls. Airbyte is a data integration/synchronization tool. It is strange that I want to trigger subsequent tasks before getting any results from AirbyteOperator. I agree that using the `op >> sensor` is more performative in terms of allocating Airflow resources, but I think it is good to leave these two options and create examples about them. Example Airbyte API returns from the `/connections/sync` responsible to trigger a job. ```json { "job": { "id": 0, "configType": "check_connection_source", "configId": "string", "createdAt": 0, "updatedAt": 0, "status": "pending" }, "attempts": [ { "attempt": { "id": 0, "status": "running", "createdAt": 0, "updatedAt": 0, "endedAt": 0, "bytesSynced": 0, "recordsSynced": 0 }, "logs": { "logLines": [ "string" ] } } ] } ``` ---------------------------------------------------------------- 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: [email protected]
