Last active
June 8, 2019 07:26
-
-
Save noklam/5aea48e95967cc2b59d13e1ab19252bb to your computer and use it in GitHub Desktop.
Airflow Blog Post https://medium.com/p/d1e322546f7d
This file contains hidden or 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
import time | |
from datetime import datetime, timedelta | |
from airflow import DAG | |
from airflow.operators.python_operator import PythonOperator | |
default_args = { | |
'owner': 'Meng Lee', | |
'start_date': datetime(2100, 1, 1, 0, 0), | |
'schedule_interval': '@daily', | |
'retries': 2, | |
'retry_delay': timedelta(minutes=1) | |
} | |
def fn_superman(): | |
print("Obtain user's reading records") | |
print("Go to the site and get latest episode information") | |
print("Compare with the user records, is it a new episode?") | |
# Murphy's Law | |
accident_occur = time.time() % 2 > 1 | |
if accident_occur: | |
print("\n Something is wrong, maybe the network is broken, who knows") | |
print("Exception and task is interrupted\n") | |
return | |
new_comic_available = time.time() % 3 < 1 | |
if new_comic_available: | |
print("Send Slack Notification") | |
print("Update User's last reading record") | |
else: | |
print("Do nothing, you have read all the episode already!") | |
with DAG('comic_app_v1', default_args=default_args) as dag: | |
superman_task = PythonOperator( | |
task_id='superman_task', | |
python_callable=fn_superman | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment