forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove providers imports from core examples (apache#12252)
Core example DAGs should not depend on any non-core dependency like providers packages. closes: apache#12247 Co-authored-by: Xiaodong DENG <[email protected]>
- Loading branch information
Showing
8 changed files
with
40 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,17 +17,27 @@ | |
# under the License. | ||
|
||
|
||
import json | ||
from typing import Dict | ||
from typing import Any, Dict | ||
|
||
import requests | ||
|
||
from airflow.decorators import dag, task | ||
from airflow.models.baseoperator import BaseOperator | ||
from airflow.operators.email import EmailOperator | ||
from airflow.providers.http.operators.http import SimpleHttpOperator | ||
from airflow.utils.dates import days_ago | ||
|
||
DEFAULT_ARGS = { | ||
"owner": "airflow", | ||
} | ||
DEFAULT_ARGS = {"owner": "airflow"} | ||
|
||
|
||
class GetRequestOperator(BaseOperator): | ||
"""Custom operator to sand GET request to provided url""" | ||
|
||
def __init__(self, *, url: str, **kwargs): | ||
super().__init__(**kwargs) | ||
self.url = url | ||
|
||
def execute(self, context): | ||
return requests.get(self.url).json() | ||
|
||
|
||
# [START dag_decorator_usage] | ||
|
@@ -39,12 +49,11 @@ def example_dag_decorator(email: str = '[email protected]'): | |
:param email: Email to send IP to. Defaults to [email protected]. | ||
:type email: str | ||
""" | ||
# Using default connection as it's set to httpbin.org by default | ||
get_ip = SimpleHttpOperator(task_id='get_ip', endpoint='get', method='GET') | ||
get_ip = GetRequestOperator(task_id='get_ip', url="http://httpbin.org/get") | ||
|
||
@task(multiple_outputs=True) | ||
def prepare_email(raw_json: str) -> Dict[str, str]: | ||
external_ip = json.loads(raw_json)['origin'] | ||
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>', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters