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 2021/07/19 02:49:09 UTC

[GitHub] [airflow] uranusjr edited a comment on issue #17073: Support defining pre/post hook for operators in a DAG at the DAG level

uranusjr edited a comment on issue #17073:
URL: https://github.com/apache/airflow/issues/17073#issuecomment-882191138


   A DAG-level solution feels limiting to me. While it sounds convenient, it is not actually very often a user would want the same hook to be executed for every task, so you’d probably end up with a lot of if-else in the function to handle different tasks in the end. A better approach to me would be to allow supplying the hook without subclassing, something like
   
   ```python
   def pre_exec(task: BaseOperator, context: Any) -> None:
       ...
   
   def different_pre_exec(task: BaseOperator, context: Any) -> None:
       ...
   
   with DAG(...) as dag:
       t1 = BashOperator(
           ...,
           before_exec_hook=pre_exec,
       )
       t2 = BashOperator(
           ...,
           before_exec_hook=pre_exec,
       )
       t3 = BashOperator(
           ...,
           before_exec_hook=different_pre_exec,
       )
   ```


-- 
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