Skip to content

Instantly share code, notes, and snippets.

@Chestermozhao
Last active November 9, 2019 12:16
Show Gist options
  • Save Chestermozhao/78fdf0a3441a2f2197ee80d0b0943648 to your computer and use it in GitHub Desktop.
Save Chestermozhao/78fdf0a3441a2f2197ee80d0b0943648 to your computer and use it in GitHub Desktop.
airflow dags and tasks
def fn_superman():
print("取得使用者的閱讀紀錄")
print("去漫畫網站看有沒有新的章節")
print("跟紀錄比較,有沒有新連載?")
# Murphy's Law
accident_occur = time.time() % 2 > 1
if accident_occur:
print("\n天有不測風雲,人有旦夕禍福")
print("工作遇到預期外狀況被中斷\n")
return
new_comic_available = time.time() % 2 > 1
if new_comic_available:
print("寄 Slack 通知")
print("更新閱讀紀錄")
else:
print("什麼都不幹,工作順利結束")
# 跟crontab前面時間相同, 也可以用crontab時間"0 0 * * *", 或者@daily
# 要用timedelta,要先import
with DAG("firstwork", default_args=default_args, schedule_interval=timedelta(days=1)) 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