coufon commented on a change in pull request #4791: [AIRFLOW-3908] Add more
Google Cloud Vision operators
URL: https://github.com/apache/airflow/pull/4791#discussion_r261423784
##########
File path: airflow/contrib/operators/gcp_vision_operator.py
##########
@@ -671,3 +672,284 @@ def execute(self, context):
timeout=self.timeout,
metadata=self.metadata,
)
+
+
+class CloudVisionAnnotateImageOperator(BaseOperator):
+ """
+ Run image detection and annotation for an image.
+
+ .. seealso::
+ For more information on how to use this operator, take a look at the
guide:
+ :ref:`howto/operator:CloudVisionAnnotateImageOperator`
+
+ :param request: (Required) Individual file annotation requests.
+ If a dict is provided, it must be of the same form as the protobuf
+ message class:`google.cloud.vision_v1.types.AnnotateImageRequest`
+ :type request: dict or google.cloud.vision_v1.types.AnnotateImageRequest
+ :param retry: (Optional) A retry object used to retry requests. If `None`
is
+ specified, requests will not be retried.
+ :type retry: google.api_core.retry.Retry
+ :param timeout: (Optional) The amount of time, in seconds, to wait for the
request to
+ complete. Note that if retry is specified, the timeout applies to each
individual
+ attempt.
+ :type timeout: float
+ :param gcp_conn_id: (Optional) The connection ID used to connect to Google
Cloud Platform.
+ :type gcp_conn_id: str
+ """
+
+ # [START vision_annotate_image_template_fields]
+ template_fields = ('request', 'gcp_conn_id')
+ # [END vision_annotate_image_template_fields]
+
+ @apply_defaults
+ def __init__(
+ self, request, retry=None, timeout=None,
gcp_conn_id='google_cloud_default', *args, **kwargs
+ ):
+ super(CloudVisionAnnotateImageOperator, self).__init__(*args, **kwargs)
+ self.request = request
+ self.retry = retry
+ self.timeout = timeout
+ self.gcp_conn_id = gcp_conn_id
+
+ def execute(self, context):
+ hook = CloudVisionHook(gcp_conn_id=self.gcp_conn_id)
Review comment:
The operators implemented previously do create and hold hook as a property,
e.g.:
return self._hook.delete_product(
Please check which is better and make it unified.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services