Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week 1 Project Submission #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions week_1/project/week_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime
from typing import List

from dagster import In, Nothing, Out, job, op, usable_as_dagster_type
from dagster import In, Nothing, Out, job, op, usable_as_dagster_type, get_dagster_logger
from pydantic import BaseModel


Expand Down Expand Up @@ -50,16 +50,29 @@ def get_s3_data(context):
return output


@op
def process_data():
pass
@op(
ins={"stocks": In(dagster_type=List[Stock])},
out={"agg_max": Out(dagster_type=Aggregation)},
description="Determine the stock with the highest value"
)
def process_data(stocks: List[Stock]) -> Aggregation:
# Find the stock with the highest value
max_stock = max(stocks, key=lambda x: x.high)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c l e a n

return Aggregation(date=max_stock.date, high=max_stock.high)


@op
def put_redis_data():
@op(
ins={"agg_max": In(dagster_type=Aggregation)},
out=None,
description="Write to Redis"
)
def put_redis_data(agg_max: Aggregation) -> None:
# Log the output
logger = get_dagster_logger()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, nice! Didn't know about a dagster logger, but makes so much sense!

logger.info(f"Write {agg_max} to Redis.")
pass


@job
def week_1_pipeline():
pass
put_redis_data(process_data(get_s3_data()))