X Tutup
The Wayback Machine - https://web.archive.org/web/20201112200137/https://github.com/apache/airflow/issues/12269
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TaskFlow API example to use `@dag` decorator #12269

Open
casassg opened this issue Nov 10, 2020 · 7 comments · May be fixed by #12271
Open

Update TaskFlow API example to use `@dag` decorator #12269

casassg opened this issue Nov 10, 2020 · 7 comments · May be fixed by #12271

Comments

@casassg
Copy link
Contributor

@casassg casassg commented Nov 10, 2020

Description

Update https://github.com/apache/airflow/blob/master/airflow/example_dags/tutorial_taskflow_api_etl.py tp use @dag decorator instead of leveraging context manager to make it more TaskFlow-y.

@turbaszek
Copy link
Contributor

@turbaszek turbaszek commented Nov 10, 2020

Do we need other example than this one?

# [START dag_decorator_usage]
@dag(default_args=DEFAULT_ARGS, schedule_interval=None, start_date=days_ago(2))
def example_dag_decorator(email: str = 'example@example.com'):
"""
DAG to send server IP to email.
:param email: Email to send IP to. Defaults to example@example.com.
:type email: str
"""
get_ip = GetRequestOperator(task_id='get_ip', url="http://httpbin.org/get")
@task(multiple_outputs=True)
def prepare_email(raw_json: Dict[str, Any]) -> Dict[str, str]:
external_ip = raw_json['origin']
return {
'subject': f'Server connected from {external_ip}',
'body': f'Seems like today your server executing Airflow is connected from IP {external_ip}<br>',
}
email_info = prepare_email(get_ip.output)
EmailOperator(
task_id='send_email', to=email, subject=email_info['subject'], html_content=email_info['body']
)

@casassg
Copy link
Contributor Author

@casassg casassg commented Nov 10, 2020

I was thinking more on having a more end to end example for the tutorial?

@kaxil
Copy link
Contributor

@kaxil kaxil commented Nov 10, 2020

We could update an example in #12170 to use the dag decorator

@eflann eflann linked a pull request that will close this issue Nov 10, 2020
@eflann
Copy link

@eflann eflann commented Nov 10, 2020

Is this what you had in mind?

@casassg
Copy link
Contributor Author

@casassg casassg commented Nov 11, 2020

@eflann yes. Commenting in the PR

@casassg
Copy link
Contributor Author

@casassg casassg commented Nov 11, 2020

@kaxil I would encourage all TaskFlow tutorials to be using @dag better? We can leave some w context manager so people undertstand it's usable in both ways. But I was indeed refering to tutorial_taskflow_api_etl as @eflann mentions

@kaxil
Copy link
Contributor

@kaxil kaxil commented Nov 11, 2020

+1 to that change

@ashb ashb added this to the Airflow 2.0.0-beta3 milestone Nov 11, 2020
@ashb ashb linked a pull request that will close this issue Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants
You can’t perform that action at this time.
X Tutup