-
Notifications
You must be signed in to change notification settings - Fork 18
Dagster Reprocessing #1384
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
Merged
bryan-harter
merged 6 commits into
IMAP-Science-Operations-Center:dagster
from
lacoak21:reprocessing_dagster
May 27, 2026
Merged
Dagster Reprocessing #1384
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
27 changes: 27 additions & 0 deletions
27
sds_data_manager/lambda_code/SDSCode/pipeline_lambdas/reprocessing_proxy.py
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 |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import json | ||
| import logging | ||
| import os | ||
|
|
||
| import boto3 | ||
|
|
||
| sqs_client = boto3.client("sqs") | ||
| QUEUE_URL = os.environ["QUEUE_URL"] | ||
| # Logger setup | ||
| logger = logging.getLogger(__name__) | ||
| logger.setLevel(logging.INFO) | ||
|
|
||
|
|
||
| def lambda_handler(event, context): | ||
| params = event.get("queryStringParameters", {}) | ||
|
|
||
| logger.info( | ||
| f"Received event: {json.dumps(event, indent=2)}. Sending to reprocessing queue" | ||
| ) | ||
|
|
||
| sqs_client.send_message( | ||
| QueueUrl=QUEUE_URL, | ||
| MessageBody=json.dumps(params), | ||
| MessageGroupId="reprocess", | ||
| ) | ||
|
|
||
| return {"statusCode": 200, "body": json.dumps({"message": "Reprocess job queued"})} |
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 |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| """Reprocessing logic.""" | ||
|
|
||
| import datetime | ||
| import json | ||
| import os | ||
|
|
||
| import boto3 | ||
| from dagster import AssetKey, AssetSelection, SensorEvaluationContext, sensor | ||
| from dagster._core.execution.backfill import PartitionBackfill | ||
|
|
||
| from sds_data_manager.orchestration.dagster_utilities import get_affected_partitions | ||
| from sds_data_manager.orchestration.dependency import ( | ||
| DependencyConfigReader, | ||
| get_kickoff_jobs, | ||
| ) | ||
| from sds_data_manager.orchestration.imap_job import partition_map | ||
|
|
||
| SQS_CLIENT = boto3.client("sqs", "us-west-2") | ||
|
|
||
|
|
||
| def read_sqs_messages(sqs_queue_url=None): | ||
| """Read SQS messages from the reprocessing queue.""" | ||
| response = SQS_CLIENT.receive_message( | ||
| QueueUrl=sqs_queue_url, | ||
| MaxNumberOfMessages=10, | ||
| WaitTimeSeconds=1, | ||
| ) | ||
| return response.get("Messages", []) | ||
|
|
||
|
|
||
| @sensor( | ||
| asset_selection=AssetSelection.all(), | ||
| minimum_interval_seconds=100, # TODO what do we want here | ||
| ) | ||
| def reprocess_sensor(context: SensorEvaluationContext): | ||
| """Sensor that triggers reprocessing backfills.""" | ||
| sqs_queue_url = os.getenv("REPROCESSING_SQS_URL") | ||
| messages = read_sqs_messages(sqs_queue_url) | ||
| reader = DependencyConfigReader() | ||
| if not messages: | ||
| return None | ||
|
|
||
| for message in messages: | ||
| params = json.loads(message["Body"]) | ||
|
|
||
| instrument = params.get("instrument") | ||
| data_level = params.get("data_level") | ||
| descriptor = params.get("descriptor") | ||
| start_date = params.get("start_date") | ||
| end_date = params.get("end_date") | ||
|
|
||
| context.log.info( | ||
| f"A reprocessing event was triggered with the parameters: {instrument=}, " | ||
| f"{data_level=}, {descriptor=}, {start_date=}, {end_date=}" | ||
| ) | ||
| if not end_date or not start_date: | ||
| raise ValueError( | ||
| "Start date and end date are required for a reprocessing Event." | ||
| ) | ||
| if not instrument: | ||
| raise ValueError("Instrument must be provided for a reprocessing event.") | ||
|
|
||
| if bool(data_level) != bool(descriptor): | ||
| raise ValueError( | ||
| "data_level and descriptor must both be provided or both None." | ||
| ) | ||
|
|
||
| if not data_level: | ||
| # If data_level is not provided, we need to reprocess all levels. | ||
| # Get the jobs that kick of each pipeline, to trigger processing | ||
| # for all levels. | ||
| root_job = get_kickoff_jobs(instrument)[0] | ||
| # Create the asset name based on the root job information | ||
| asset_name = f"{instrument}_{root_job.data_type}_{root_job.descriptor}" | ||
| partition = root_job.partition | ||
| else: | ||
| # If data_level is provided (and therefore descriptor) construct the | ||
| # asset name using the input parameters | ||
| asset_name = f"{instrument}_{data_level}_{descriptor}" | ||
|
Contributor
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. Bryan had issue with assets name with |
||
| # Get the partition type from the dependency config | ||
| partition = reader.config[(instrument, data_level, descriptor)].partition | ||
|
|
||
| # Get the partitions definition based on the DependencyNode | ||
| partition_def = partition_map.get(partition) | ||
| # convert start and end date to datetime | ||
| start_date = datetime.datetime.strptime(start_date, "%Y%m%d").replace( | ||
| tzinfo=datetime.timezone.utc | ||
| ) | ||
| end_date = datetime.datetime.strptime(end_date, "%Y%m%d").replace( | ||
| tzinfo=datetime.timezone.utc | ||
| ) | ||
|
|
||
| # Determine the affected partitions based on the start_date and end_date | ||
| partition_keys = get_affected_partitions( | ||
| context, partition_def, start_date, end_date | ||
| ) | ||
| if not partition_keys: | ||
| return None | ||
| context.log.info( | ||
| f"Reprocessing asset {asset_name} across {partition_keys} partitions" | ||
| ) | ||
|
|
||
| backfill = PartitionBackfill.from_asset_partitions( | ||
| backfill_id=f"reprocess-{instrument}-{int(datetime.datetime.now().timestamp())}", | ||
| asset_graph=context.repository_def.asset_graph, | ||
| partition_names=partition_keys, | ||
| asset_selection=[AssetKey(asset_name)], | ||
| backfill_timestamp=datetime.datetime.now(datetime.timezone.utc).timestamp(), | ||
| tags={ | ||
| "instrument": instrument, | ||
| "descriptor": descriptor or "", | ||
| "data_level": data_level or "", | ||
| }, | ||
| dynamic_partitions_store=context.instance, | ||
| all_partitions=False, | ||
| title=None, | ||
| description=None, | ||
| run_config=None, | ||
| ) | ||
|
|
||
| context.instance.add_backfill(backfill) | ||
|
|
||
| SQS_CLIENT.delete_message( | ||
| QueueUrl=sqs_queue_url, | ||
| ReceiptHandle=message["ReceiptHandle"], | ||
| ) | ||
|
|
||
| return None | ||
|
|
||
|
|
||
| sensors = [reprocess_sensor] | ||
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
Oops, something went wrong.
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.
I don't know the specific but really easy to follow!