Skip to content

[DCP Preprocessor] Move preprocessor to workflow - part 1#621

Open
gmechali wants to merge 2 commits into
datacommonsorg:masterfrom
gmechali:dcpbridge2
Open

[DCP Preprocessor] Move preprocessor to workflow - part 1#621
gmechali wants to merge 2 commits into
datacommonsorg:masterfrom
gmechali:dcpbridge2

Conversation

@gmechali

@gmechali gmechali commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

This piece just reworks the output of the preprocessor to store the workflow's input in GCS so the workflow can propagate it to dataflow.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request replaces the direct invocation of trigger_ingestion_workflow with a new _handle_workflow_handoff method in simple/stats/runner.py to write processed import metadata to a GCS handshake JSON file. Feedback suggests validating that GCP_SPANNER_INSTANCE_ID and GCP_SPANNER_DATABASE_NAME are set before writing the handshake payload to prevent downstream workflow steps from failing silently.

Comment thread simple/stats/runner.py
Comment on lines +252 to +271
workflow_id = os.getenv("WORKFLOW_EXECUTION_ID")
temp_location = os.getenv("TEMP_LOCATION", "")

if not workflow_id or not temp_location.startswith("gs://"):
logging.warning(
"WORKFLOW_EXECUTION_ID not set or TEMP_LOCATION (%s) is not a GCS path. Skipping GCS handshake.",
temp_location)
return

raw_import_name = "_".join(item["importName"] for item in self.trigger_workflow_info)
sanitized_import_name = re.sub(r'[^a-zA-Z0-9_-]', '_', raw_import_name)[:64]

handshake_payload = {
"spannerInstanceId": os.getenv("GCP_SPANNER_INSTANCE_ID", ""),
"spannerDatabaseId": os.getenv("GCP_SPANNER_DATABASE_NAME", ""),
"importName": sanitized_import_name,
"importList": json.dumps(self.trigger_workflow_info),
"tempLocation": temp_location,
"region": os.getenv("REGION", "")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

When WORKFLOW_EXECUTION_ID is set, the preprocessor is running as part of the ingestion workflow. In this context, GCP_SPANNER_INSTANCE_ID and GCP_SPANNER_DATABASE_NAME are required environment variables. If they are missing, writing an incomplete handshake payload with empty strings will cause downstream workflow steps to fail silently or unexpectedly. It is safer to validate these variables and log an error/skip the handshake if they are not set.

    workflow_id = os.getenv("WORKFLOW_EXECUTION_ID")
    temp_location = os.getenv("TEMP_LOCATION", "")

    if not workflow_id or not temp_location.startswith("gs://"):
      logging.warning(
          "WORKFLOW_EXECUTION_ID not set or TEMP_LOCATION (%s) is not a GCS path. Skipping GCS handshake.",
          temp_location)
      return

    spanner_instance = os.getenv("GCP_SPANNER_INSTANCE_ID")
    spanner_database = os.getenv("GCP_SPANNER_DATABASE_NAME")
    if not spanner_instance or not spanner_database:
      logging.error(
          "GCP_SPANNER_INSTANCE_ID or GCP_SPANNER_DATABASE_NAME not set. Skipping GCS handshake.")
      return

    raw_import_name = "_".join(item["importName"] for item in self.trigger_workflow_info)
    sanitized_import_name = re.sub(r'[^a-zA-Z0-9_-]', '_', raw_import_name)[:64]

    handshake_payload = {
        "spannerInstanceId": spanner_instance,
        "spannerDatabaseId": spanner_database,
        "importName": sanitized_import_name,
        "importList": json.dumps(self.trigger_workflow_info),
        "tempLocation": temp_location,
        "region": os.getenv("REGION", "")
    }

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant