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
from prefect import task, flow | |
from prefect import get_run_logger | |
from typing import Any | |
@task | |
def say_hi(user_name: str, question: str, answer: Any) -> None: | |
logger = get_run_logger() | |
logger.info("Hello from Prefect, %s! 👋", user_name) | |
logger.info("The answer to the %s question is %s! 🤖", question, answer) |
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
import asyncio | |
import textwrap | |
from client import from_dict | |
from dotenv import load_dotenv | |
import os | |
load_dotenv() |
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
from airflow.decorators import dag, task | |
import pendulum | |
from airflow_prefect import send_prefect_event_callback | |
@dag( | |
schedule=None, | |
start_date=pendulum.datetime(2023, 1, 24, tz="UTC"), | |
catchup=False, |
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
from airflow.decorators import dag, task | |
import pendulum | |
from airflow_prefect import send_prefect_event_callback | |
@dag( | |
schedule=None, | |
start_date=pendulum.datetime(2023, 1, 24, tz="UTC"), | |
catchup=False, |
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
from airflow.hooks.base import BaseHook | |
import pendulum | |
import requests | |
import uuid | |
def get_prefect_event(context): | |
prefect_event = [ | |
{ | |
"id": str(uuid.uuid4()), |
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
from airflow.hooks.base import BaseHook | |
import pendulum | |
import requests | |
import uuid | |
def get_prefect_event(context): | |
prefect_event = [ | |
{ | |
"id": str(uuid.uuid4()), |
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
from prefect import get_run_logger | |
def enable_loguru_support() -> None: | |
"""Redirect loguru logging messages to the prefect run logger. | |
This function should be called from within a Prefect task or flow before calling any module that uses loguru. | |
This function can be safely called multiple times. | |
Example Usage: |
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
from prefect import flow, task | |
from loguru import logger | |
from prefect_utils.loguru import enable_loguru_support | |
def mycustom_function(): | |
logger.info("I'm a custom function") | |
@task |
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
from datetime import timedelta | |
from prefect.tasks import task_input_hash | |
from prefect import task, flow | |
import time | |
from prefect.context import get_run_context | |
def cache_within_flow_run(context, parameters): | |
id_ = get_run_context().flow_run.dict().get('id') | |
key = f"{id_}-{task_input_hash(context, parameters)}" |
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
from prefect import task, flow, get_run_logger | |
from prefect_dask import DaskTaskRunner | |
import time | |
@task | |
def extract() -> list: | |
logger = get_run_logger() | |
logger.info("extract") | |
return [1, 2, 3, 4, 5, 6] |