You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "pankajkoti (via GitHub)" <gi...@apache.org> on 2023/05/07 07:18:22 UTC
[GitHub] [airflow] pankajkoti commented on a diff in pull request #31081: Add deferrable mode to `GCSUploadSessionCompleteSensor`
pankajkoti commented on code in PR #31081:
URL: https://github.com/apache/airflow/pull/31081#discussion_r1186796994
##########
airflow/providers/google/cloud/sensors/gcs.py:
##########
@@ -514,3 +518,39 @@ def poke(self, context: Context) -> bool:
return self.is_bucket_updated(
set(self._get_gcs_hook().list(self.bucket, prefix=self.prefix)) # type: ignore[union-attr]
)
+
+ def execute(self, context: Context) -> None:
+ """Airflow runs this method on the worker and defers using the trigger."""
+ hook_params = {"impersonation_chain": self.impersonation_chain}
+
+ if not self.deferrable:
+ super().execute(context)
+ else:
+ if not self.poke(context=context):
+ self.defer(
+ timeout=timedelta(seconds=self.timeout),
+ trigger=GCSUploadSessionTrigger(
+ bucket=self.bucket,
+ prefix=self.prefix,
+ poke_interval=self.poke_interval,
+ google_cloud_conn_id=self.google_cloud_conn_id,
+ inactivity_period=self.inactivity_period,
+ min_objects=self.min_objects,
+ previous_objects=self.previous_objects,
+ allow_delete=self.allow_delete,
+ hook_params=hook_params,
+ ),
+ method_name="execute_complete",
+ )
Review Comment:
```suggestion
if not self.deferrable:
super().execute(context)
return
if not self.poke(context=context):
hook_params = {"impersonation_chain": self.impersonation_chain}
self.defer(
timeout=timedelta(seconds=self.timeout),
trigger=GCSUploadSessionTrigger(
bucket=self.bucket,
prefix=self.prefix,
poke_interval=self.poke_interval,
google_cloud_conn_id=self.google_cloud_conn_id,
inactivity_period=self.inactivity_period,
min_objects=self.min_objects,
previous_objects=self.previous_objects,
allow_delete=self.allow_delete,
hook_params=hook_params,
),
method_name="execute_complete",
)
```
Suggestion to reduce branch complexity.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org