You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/05/05 16:50:37 UTC
[GitHub] [airflow] evgenyshulman commented on pull request #8651: [AIP-31] [AIRFLOW-8058] Retrieve current execution context without altering function's signature
evgenyshulman commented on pull request #8651:
URL: https://github.com/apache/airflow/pull/8651#issuecomment-624172030
continuing on this discussion: actually you have a really great usecase for this feature - https://github.com/apache/airflow/pull/8432
this feature will enable to provide GCP context in the runtime without change every and every operator ( right now you have change Bash and Python, but what about all others? )
so useful example for contextmanager can be something like this ( it can be part of airflow library, or just defined by the user in place accordingly to his requirements)
```@contextlib.contextmanager
def gcp_context(context):
if not ( "some condition on config that provide what gcp project to use ( maybe conf.get('gcp', 'project_id', None)..)"):
yield None
return
gcp_gcp_delegate_to = ...
gcp_conn_id = ...
with TemporaryDirectory(prefix='airflowtmp') as tmp_dir:
try:
from airflow.providers.google.common.hooks.base_google import GoogleBaseHook
except ImportError:
raise AirflowException(
'Additional packages gcp are not installed. Please install it to use gcp_conn_id '
'parameter.'
'For more information, please look at: '
f'{DOC_BASE_URL}/installation' )
with GoogleBaseHook(gcp_conn_id=gcp_conn_id, delegate_to=gcp_gcp_delegate_to).provide_authorized_gcloud() as gcp_context :
yield gcp_context # will not be in use
```
( based on https://github.com/apache/airflow/pull/8432 implementation)
----------------------------------------------------------------
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:
users@infra.apache.org