Imbruced commented on code in PR #41122:
URL: https://github.com/apache/airflow/pull/41122#discussion_r1705427834
##########
airflow/providers/airbyte/operators/airbyte.py:
##########
@@ -73,47 +74,39 @@ def __init__(
self.connection_id = connection_id
self.timeout = timeout
self.api_version = api_version
- self.api_type = api_type
self.wait_seconds = wait_seconds
self.asynchronous = asynchronous
self.deferrable = deferrable
def execute(self, context: Context) -> None:
"""Create Airbyte Job and wait to finish."""
- hook = AirbyteHook(
- airbyte_conn_id=self.airbyte_conn_id,
api_version=self.api_version, api_type=self.api_type
- )
+ hook = AirbyteHook(airbyte_conn_id=self.airbyte_conn_id,
api_version=self.api_version)
job_object =
hook.submit_sync_connection(connection_id=self.connection_id)
- if self.api_type == "config":
- self.job_id = job_object.json()["job"]["id"]
- state = job_object.json()["job"]["status"]
- else:
- self.job_id = job_object.json()["jobId"]
- state = job_object.json()["status"]
+ self.job_id = job_object.job_id
+ state = job_object.status
end_time = time.time() + self.timeout
Review Comment:
nit: what do you think about keeping happy path on the left with early
return ?
```python
def execute(self, context: Context) -> None:
"""Create Airbyte Job and wait to finish."""
hook = AirbyteHook(airbyte_conn_id=self.airbyte_conn_id,
api_version=self.api_version)
job_object =
hook.submit_sync_connection(connection_id=self.connection_id)
self.job_id = job_object.job_id
state = job_object.status
end_time = time.time() + self.timeout
self.log.info("Job %s was submitted to Airbyte Server", self.job_id)
if not self.deferrable:
hook.wait_for_job(job_id=self.job_id,
wait_seconds=self.wait_seconds, timeout=self.timeout)
if not self.deferrable or self.asynchronous:
self.log.info("Job %s completed successfully", self.job_id)
return self.job_id
if state in (JobStatusEnum.RUNNING, JobStatusEnum.PENDING,
JobStatusEnum.INCOMPLETE):
self.defer(
timeout=self.execution_timeout,
trigger=AirbyteSyncTrigger(
conn_id=self.airbyte_conn_id,
job_id=self.job_id,
end_time=end_time,
poll_interval=60,
),
method_name="execute_complete",
)
elif state == JobStatusEnum.SUCCEEDED:
self.log.info("Job %s completed successfully", self.job_id)
return
elif state == JobStatusEnum.FAILED:
raise AirflowException(f"Job failed:\n{self.job_id}")
elif state == JobStatusEnum.CANCELLED:
raise AirflowException(f"Job was cancelled:\n{self.job_id}")
else:
raise AirflowException(
f"Encountered unexpected state `{state}` for job_id
`{self.job_id}"
)
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]