Skip to content

Instantly share code, notes, and snippets.

@noklam
Last active June 8, 2019 07:26
Show Gist options
  • Save noklam/5aea48e95967cc2b59d13e1ab19252bb to your computer and use it in GitHub Desktop.
Save noklam/5aea48e95967cc2b59d13e1ab19252bb to your computer and use it in GitHub Desktop.
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