Skip to content
This repository was archived by the owner on Dec 8, 2023. It is now read-only.
This repository was archived by the owner on Dec 8, 2023. It is now read-only.

Airflow migration to modern syntax #31

@morgante

Description

@morgante

We would like a pattern that helps to modernize from older Airflow syntax to modern decorator-based syntax by replacing the DAG call with decorators and bitwise >> chaining with chain().

def do_my_thing() -> DAG:
  dag = DAG(description="My cool DAG")
  
  def do_thing(**context: T.Any) -> bool:
        return not aws_rds.db_exists(
            region=get_variable(EnvVarKeys.TARGET),
            )
   def do_thing_two(**context: T.Any) -> bool:
        pass

  other_operator = ShortCircuitOperator(
        dag=dag,
        task_id='do_db_thing',
        python_callable=do_thing,
        provide_context=True,
     )
  operator_two = PythonOperator(python_callable=do_thing_two)
  
  other_operator \
       >> operator_two

Output:

@dag(description="My cool DAG", schedule_interval=None)
def do_my_thing():
    @task
    def do_thing():
        # You might want to instantiate AwsRDSHook and use it here, or use a specific Airflow provider's hook.
        return not AwsRDSHook().db_exists(
            region=get_variable(EnvVarKeys.TARGET)
        )

    @task
    def do_thing_two():
        pass

    chain(do_thing, do_thing_two)

Acceptance criteria

  1. Working pattern that can be applied to handle both cases (in a .md file)
  2. At least 5 test cases

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions