-
Notifications
You must be signed in to change notification settings - Fork 7
update to new sdk #9
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
Open
miwialex
wants to merge
1
commit into
main
Choose a base branch
from
rm/sdk-update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,7 +13,7 @@ Process customer signup data from CSV files with validation, cleaning, and stati | |||||
|
|
||||||
| ## Features | ||||||
|
|
||||||
| - **Subtask Execution**: Demonstrates calling tasks from other tasks using `await` | ||||||
| - **Subtask Execution**: Demonstrates running tasks from other tasks with `ctx.step` | ||||||
| - **Extract**: Read data from CSV files (extensible to APIs, databases) | ||||||
| - **Transform**: Validate records with comprehensive error tracking | ||||||
| - **Load**: Compute statistics and prepare aggregated insights | ||||||
|
|
@@ -163,23 +163,23 @@ This demonstrates how the pipeline handles data quality issues. | |||||
| - Validates age range (0-120) | ||||||
| - Returns cleaned data with error tracking | ||||||
|
|
||||||
| **`transform_batch`**: Processes all records by calling `validate_record` as a subtask for each one: | ||||||
| **`transform_batch`**: Processes all records by running `validate_record` as a subtask for each one: | ||||||
| ```python | ||||||
| for record in records: | ||||||
| # Call validate_record as a subtask | ||||||
| validated = await validate_record(record) | ||||||
| # Run validate_record as a subtask on its own compute | ||||||
| validated = await ctx.step(validate_record, record) | ||||||
| ``` | ||||||
| This demonstrates **calling subtasks in a loop** for batch processing. | ||||||
| This demonstrates **stepping subtasks in a loop** for batch processing. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This right here is one of my complaints with
Suggested change
|
||||||
|
|
||||||
| **`compute_statistics`**: Aggregates valid records to produce: | ||||||
| - Country distribution | ||||||
| - Age statistics (min, max, average) | ||||||
| - Data quality metrics | ||||||
|
|
||||||
| **`run_etl_pipeline`**: Main orchestrator that calls three subtasks sequentially: | ||||||
| 1. `await extract_csv_data(source_file)` - Extract data | ||||||
| 2. `await transform_batch(raw_records)` - Validate records (which calls `validate_record` for each) | ||||||
| 3. `await compute_statistics(valid_records)` - Generate insights | ||||||
| **`run_etl_pipeline`**: Main orchestrator that runs three subtasks sequentially: | ||||||
| 1. `await ctx.step(extract_csv_data, source_file)` - Extract data | ||||||
| 2. `await ctx.step(transform_batch, raw_records)` - Validate records (which steps `validate_record` for each) | ||||||
| 3. `await ctx.step(compute_statistics, valid_records)` - Generate insights | ||||||
|
|
||||||
| This demonstrates **sequential subtask orchestration** for multi-stage pipelines. | ||||||
|
|
||||||
|
|
@@ -188,7 +188,7 @@ This demonstrates **sequential subtask orchestration** for multi-stage pipelines | |||||
| **Add Database Loading**: | ||||||
| ```python | ||||||
| @app.task | ||||||
| async def load_to_database(records: list[dict]) -> dict: | ||||||
| async def load_to_database(ctx: TaskContext, records: list[dict]) -> dict: | ||||||
| # Connect to database | ||||||
| # Insert records | ||||||
| # Return confirmation | ||||||
|
|
@@ -198,7 +198,7 @@ async def load_to_database(records: list[dict]) -> dict: | |||||
| **Add API Data Source**: | ||||||
| ```python | ||||||
| @app.task | ||||||
| async def extract_from_api(api_url: str) -> list[dict]: | ||||||
| async def extract_from_api(ctx: TaskContext, api_url: str) -> list[dict]: | ||||||
| # Fetch from REST API | ||||||
| # Parse JSON response | ||||||
| # Return records | ||||||
|
|
@@ -210,9 +210,9 @@ async def extract_from_api(api_url: str) -> list[dict]: | |||||
| import asyncio | ||||||
|
|
||||||
| @app.task | ||||||
| async def transform_batch_parallel(records: list[dict]) -> dict: | ||||||
| async def transform_batch_parallel(ctx: TaskContext, records: list[dict]) -> dict: | ||||||
| # Validate all records in parallel | ||||||
| tasks = [validate_record(record) for record in records] | ||||||
| tasks = [ctx.step(validate_record, record) for record in records] | ||||||
| results = await asyncio.gather(*tasks) | ||||||
| # Aggregate results | ||||||
| return results | ||||||
|
|
||||||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.