Skip to content
Merged
Show file tree
Hide file tree
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
198 changes: 45 additions & 153 deletions .github/request-simulation-model-versions.sh
Original file line number Diff line number Diff line change
@@ -1,80 +1,38 @@
#! /usr/bin/env bash
#!/usr/bin/env bash

set -e

# Google Cloud Workflow execution script
# Usage: ./request-simulation-model-versions.sh -b <bucket_name> -us <us_version> -uk <uk_version> [-t timeout] [-i interval]
# Modal Gateway version check script
# Verifies that the US and UK package versions used by API v1 are deployed
# in the Modal simulation API before allowing API v1 deployment to proceed.
#
# Usage: ./request-simulation-model-versions.sh -us <us_version> -uk <uk_version>

GATEWAY_URL="https://policyengine--policyengine-simulation-gateway-web-app.modal.run"

usage() {
echo "Usage: $0 -b <bucket_name> -us <us_version> -uk <uk_version> [-t timeout] [-i interval]"
echo "Usage: $0 -us <us_version> -uk <uk_version>"
echo ""
echo "Required flags:"
echo " -b bucket_name - GCS bucket name"
echo " -us us_version - US package version"
echo " -uk uk_version - UK package version"
echo ""
echo "Optional flags:"
echo " -t timeout_seconds - Maximum wait time in seconds (default: 300)"
echo " -i check_interval - Check interval in seconds (default: 10)"
echo " -h help - Show this help message"
echo ""
echo "Example:"
echo " $0 -b my-bucket -us v1.2.3 -uk v1.2.4"
echo " $0 -b my-bucket -us v1.2.3 -uk v1.2.4 -t 600 -i 15"
echo " -us us_version - US package version (e.g., 1.459.0)"
echo " -uk uk_version - UK package version (e.g., 2.65.9)"
exit 1
}

# Initialize variables
BUCKET_NAME=""
US_VERSION=""
UK_VERSION=""
TIMEOUT_SECONDS="300"
CHECK_INTERVAL="10"

# Parse command line arguments
while [ $# -gt 0 ]; do
case "$1" in
-b)
if [ -z "$2" ]; then
echo "Error: -b requires a bucket name"
exit 1
fi
BUCKET_NAME="$2"
shift 2
;;
-us)
if [ -z "$2" ]; then
echo "Error: -us requires a US version"
exit 1
fi
US_VERSION="$2"
shift 2
;;
-uk)
if [ -z "$2" ]; then
echo "Error: -uk requires a UK version"
exit 1
fi
UK_VERSION="$2"
shift 2
;;
-t)
if [ -z "$2" ]; then
echo "Error: -t requires a timeout value"
exit 1
fi
TIMEOUT_SECONDS="$2"
shift 2
;;
-i)
if [ -z "$2" ]; then
echo "Error: -i requires an interval value"
exit 1
fi
CHECK_INTERVAL="$2"
shift 2
;;
-h)
-h|--help)
usage
;;
*)
Expand All @@ -84,111 +42,45 @@ while [ $# -gt 0 ]; do
esac
done

# Validate required arguments
if [ -z "$BUCKET_NAME" ] || [ -z "$US_VERSION" ] || [ -z "$UK_VERSION" ]; then
echo "Error: Missing required arguments"
echo "bucket_name (-b), us_version (-us), and uk_version (-uk) are required"
if [ -z "$US_VERSION" ] || [ -z "$UK_VERSION" ]; then
echo "Error: Both -us and -uk versions are required"
usage
fi

# Validate numeric arguments
if ! [[ "$TIMEOUT_SECONDS" =~ ^[0-9]+$ ]] || ! [[ "$CHECK_INTERVAL" =~ ^[0-9]+$ ]]; then
echo "Error: timeout_seconds and check_interval must be positive integers"
exit 1
fi

# Configuration
PROJECT_ID="prod-api-v2-c4d5"
WORKFLOW_LOCATION="us-central1"
WORKFLOW_NAME="wait-for-country-packages"

echo "Starting workflow execution..."
echo "Project: $PROJECT_ID"
echo "Location: $WORKFLOW_LOCATION"
echo "Workflow: $WORKFLOW_NAME"
echo "Bucket: $BUCKET_NAME"
echo "US Version: $US_VERSION"
echo "UK Version: $UK_VERSION"
echo "Timeout: ${TIMEOUT_SECONDS}s"
echo "Check Interval: ${CHECK_INTERVAL}s"

# Build input JSON
INPUT_JSON=$(cat <<EOF
{
"bucket_name": "$BUCKET_NAME",
"us_country_package_version": "$US_VERSION",
"uk_country_package_version": "$UK_VERSION",
"timeout_seconds": $TIMEOUT_SECONDS,
"check_interval": $CHECK_INTERVAL
}
EOF
)

echo "Input: $INPUT_JSON"

# Execute workflow
echo "Executing workflow..."
EXECUTION_RESULT=$(gcloud workflows execute "$WORKFLOW_NAME" \
--project="$PROJECT_ID" \
--location="$WORKFLOW_LOCATION" \
--data="$INPUT_JSON" \
--format="json")
echo "Checking Modal simulation API versions..."
echo " Gateway: $GATEWAY_URL"
echo " Expected US version: $US_VERSION"
echo " Expected UK version: $UK_VERSION"
echo ""

# Extract execution name
EXECUTION_NAME=$(echo "$EXECUTION_RESULT" | jq -r '.name')
# Query the gateway for deployed versions
VERSIONS_RESPONSE=$(curl -s "${GATEWAY_URL}/versions")

if [ -z "$EXECUTION_NAME" ] || [ "$EXECUTION_NAME" = "null" ]; then
echo "Failed to start workflow execution"
echo "$EXECUTION_RESULT"
if [ -z "$VERSIONS_RESPONSE" ]; then
echo "ERROR: Failed to fetch versions from gateway"
exit 1
fi

echo "Execution started: $EXECUTION_NAME"

# Monitor execution state
START_TIME=$(date +%s)
echo "Monitoring execution state..."
# Check if US version is deployed
US_DEPLOYED=$(echo "$VERSIONS_RESPONSE" | jq -r --arg v "$US_VERSION" '.us[$v] // empty')
if [ -z "$US_DEPLOYED" ]; then
echo "ERROR: US version $US_VERSION is NOT deployed in Modal simulation API"
echo "Available US versions:"
echo "$VERSIONS_RESPONSE" | jq -r '.us | keys[]'
exit 1
fi
echo "US version $US_VERSION is deployed (app: $US_DEPLOYED)"

# Check if UK version is deployed
UK_DEPLOYED=$(echo "$VERSIONS_RESPONSE" | jq -r --arg v "$UK_VERSION" '.uk[$v] // empty')
if [ -z "$UK_DEPLOYED" ]; then
echo "ERROR: UK version $UK_VERSION is NOT deployed in Modal simulation API"
echo "Available UK versions:"
echo "$VERSIONS_RESPONSE" | jq -r '.uk | keys[]'
exit 1
fi
echo "UK version $UK_VERSION is deployed (app: $UK_DEPLOYED)"

while true; do
# Get current execution state
EXECUTION_STATUS=$(gcloud workflows executions wait "$EXECUTION_NAME" \
--location="$WORKFLOW_LOCATION" \
--format="json")

STATE=$(echo "$EXECUTION_STATUS" | jq -r '.state')

echo "Current state: $STATE"

# Check if execution is complete
if [ "$STATE" = "SUCCEEDED" ]; then
echo "SUCCESS: Workflow completed successfully"
RESULT=$(echo "$EXECUTION_STATUS" | jq -r '.result // empty')
if [ -n "$RESULT" ] && [ "$RESULT" != "null" ]; then
echo "Result: $RESULT"
fi
exit 0
elif [ "$STATE" = "FAILED" ]; then
echo "FAILED: Workflow execution failed"
ERROR=$(echo "$EXECUTION_STATUS" | jq -r '.error // empty')
if [ -n "$ERROR" ] && [ "$ERROR" != "null" ]; then
echo "Error: $ERROR"
fi
exit 1
elif [ "$STATE" = "CANCELLED" ]; then
echo "CANCELLED: Workflow execution was cancelled"
exit 1
fi

# Check monitoring timeout
CURRENT_TIME=$(date +%s)
ELAPSED=$((CURRENT_TIME - START_TIME))

if [ $ELAPSED -ge $((TIMEOUT_SECONDS + 60)) ]; then
echo "TIMEOUT: Monitoring timeout exceeded"
echo "Workflow may still be running. Check Google Cloud Console for status."
exit 1
fi

# Wait before next check
sleep "$CHECK_INTERVAL"
done
echo ""
echo "SUCCESS: Both US and UK versions are deployed and ready"
exit 0
6 changes: 1 addition & 5 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,14 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: GCP authentication
uses: "google-github-actions/auth@v2"
with:
credentials_json: "${{ secrets.GCP_SA_KEY }}"
- name: Install dependencies (required for finding API model versions)
run: make install
- name: Install jq (required only for GitHub Actions)
run: sudo apt-get install -y jq
- name: Find API model versions and write to environment variable
run: python3 .github/find-api-model-versions.py
- name: Ensure full API and simulation API model versions are in sync
run: ".github/request-simulation-model-versions.sh -b prod-api-v2-c4d5-metadata -us ${{ env.US_VERSION }} -uk ${{ env.UK_VERSION }}"
run: ".github/request-simulation-model-versions.sh -us ${{ env.US_VERSION }} -uk ${{ env.UK_VERSION }}"
versioning:
name: Update versioning
if: |
Expand Down
7 changes: 7 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- bump: patch
changes:
removed:
- Deprecated GCP simulation API client and factory pattern
- google-cloud-workflows dependency
- GCP-related simulation constants
- Deprecated GCP Workflows execution script
18 changes: 2 additions & 16 deletions policyengine_api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,16 @@
],
}

# Simulation execution status constants
# GCP Workflow execution states (from google.cloud.workflows.executions_v1.Execution.State)
GCP_EXECUTION_STATUS_ACTIVE = "ACTIVE"
GCP_EXECUTION_STATUS_SUCCEEDED = "SUCCEEDED"
GCP_EXECUTION_STATUS_FAILED = "FAILED"
GCP_EXECUTION_STATUS_CANCELLED = "CANCELLED"

# Modal simulation API status values
MODAL_EXECUTION_STATUS_SUBMITTED = "submitted"
MODAL_EXECUTION_STATUS_RUNNING = "running"
MODAL_EXECUTION_STATUS_COMPLETE = "complete"
MODAL_EXECUTION_STATUS_FAILED = "failed"

# Status groupings for EconomyService._handle_execution_state()
EXECUTION_STATUSES_SUCCESS = (
GCP_EXECUTION_STATUS_SUCCEEDED,
MODAL_EXECUTION_STATUS_COMPLETE,
)
EXECUTION_STATUSES_FAILURE = (
GCP_EXECUTION_STATUS_FAILED,
MODAL_EXECUTION_STATUS_FAILED,
)
EXECUTION_STATUSES_SUCCESS = (MODAL_EXECUTION_STATUS_COMPLETE,)
EXECUTION_STATUSES_FAILURE = (MODAL_EXECUTION_STATUS_FAILED,)
EXECUTION_STATUSES_PENDING = (
GCP_EXECUTION_STATUS_ACTIVE,
MODAL_EXECUTION_STATUS_SUBMITTED,
MODAL_EXECUTION_STATUS_RUNNING,
)
Expand Down
1 change: 0 additions & 1 deletion policyengine_api/data/congressional_districts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from pydantic import BaseModel, Field


# Mapping of state codes to full state names
STATE_CODE_TO_NAME = {
"AL": "Alabama",
Expand Down
Loading
Loading