Skip to content

Instantly share code, notes, and snippets.

@cicdw
Last active February 22, 2019 20:20
Show Gist options
  • Save cicdw/e6846e36c2a9bafe60683016ef45538d to your computer and use it in GitHub Desktop.
Save cicdw/e6846e36c2a9bafe60683016ef45538d to your computer and use it in GitHub Desktop.
Diff after adding in Prefect code
- import os
...
+ import prefect
+ from prefect import Flow, Parameter, task
+ from prefect.client import Secret
+ from prefect.schedules import CronSchedule

+ @task
def get_standup_date():
    ...
-   now = datetime.datetime.utcnow()
+   now = prefect.context["scheduled_start_time"]
    ...

+ @task(max_retries=2, retry_delay=datetime.timedelta(minutes=1))
def get_latest_updates(date):
    ...
    
+ @task(max_retries=2, retry_delay=datetime.timedelta(minutes=1))
def post_standup(updates, channel):
    ...
-   TOKEN = os.environ.get("MARVIN_TOKEN") # a common pattern for safely storing secrets
+   TOKEN = Secret("MARVIN_TOKEN").get() # use a Prefect Secret instead
    ...


+ with Flow(name="post-standup", schedule=weekday_schedule) as flow:
+    standup_channel = Parameter("standup_channel", default="XXXXXXXXX")
+    updates = get_latest_updates(get_standup_date)
+    res = post_standup(updates, standup_channel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment