-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from NYPL/include-recovery-data
Query Redshift to find missing and unrecovered data from the past 30 days and query ShopperTrak for it
- Loading branch information
Showing
12 changed files
with
799 additions
and
138 deletions.
There are no files selected for viewing
This file contains 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,58 @@ | ||
name: Deploy to production if tagged as production release | ||
|
||
on: | ||
release: | ||
types: [ released ] | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
jobs: | ||
check_production_tag: | ||
name: Check if the release is tagged as production | ||
runs-on: ubuntu-latest | ||
outputs: | ||
has_production_tag: ${{ steps.check-production-tag.outputs.run_jobs }} | ||
steps: | ||
- name: check production tag ${{ github.ref }} | ||
id: check-production-tag | ||
run: | | ||
if [[ ${{ github.ref }} =~ refs\/tags\/production ]]; then | ||
echo "run_jobs=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "run_jobs=false" >> $GITHUB_OUTPUT | ||
fi | ||
publish_production: | ||
needs: [ check_production_tag ] | ||
if: needs.check_production_tag.outputs.has_production_tag == 'true' | ||
name: Publish image to ECR and update ECS stack | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole | ||
aws-region: us-east-1 | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
|
||
- name: Build, tag, and push image to Amazon ECR | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
ECR_REPOSITORY: location-visits-poller | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: | | ||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:production-latest | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:production-latest | ||
- name: Force ECS Update | ||
run: | | ||
aws ecs update-service --cluster location-visits-poller-production --service location-visits-poller-production --force-new-deployment |
This file contains 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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 2024-04-24 -- v1.0.0 | ||
### Added | ||
- Perform recovery queries on past thirty days of missing data | ||
|
||
## 2024-04-04 -- v0.0.1 | ||
### Added | ||
- Initial commit without any recovery queries |
This file contains 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 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 |
---|---|---|
@@ -1,15 +1,20 @@ | ||
--- | ||
PLAINTEXT_VARIABLES: | ||
AWS_REGION: us-east-1 | ||
REDSHIFT_DB_NAME: dev | ||
SHOPPERTRAK_API_BASE_URL: https://stws.shoppertrak.com/Traffic/Customer/v1.0/service/ | ||
LOCATION_VISITS_SCHEMA_URL: | ||
LOCATION_VISITS_SCHEMA_URL: https://qa-platform.nypl.org/api/v0.1/current-schemas/LocationVisits | ||
MAX_RETRIES: 3 | ||
LOG_LEVEL: info | ||
LAST_POLL_DATE: 2024-03-25 | ||
END_DATE: 2024-03-27 | ||
IGNORE_CACHE: True | ||
IGNORE_KINESIS: True | ||
IGNORE_UPDATE: True | ||
ENCRYPTED_V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BVBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDO0tpI+96T7sLWve0QIBEIAoq3KNN5xKl69tvlBReWIegDOru/Ejk1yxRwCoEd3f/J4A8FLm+vfVng== | ||
... |
This file contains 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,18 @@ | ||
--- | ||
PLAINTEXT_VARIABLES: | ||
AWS_REGION: us-east-1 | ||
REDSHIFT_DB_NAME: production | ||
SHOPPERTRAK_API_BASE_URL: https://stws.shoppertrak.com/Traffic/Customer/v1.0/service/ | ||
LOCATION_VISITS_SCHEMA_URL: https://platform.nypl.org/api/v0.1/current-schemas/LocationVisits | ||
S3_BUCKET: bic-poller-states-production | ||
S3_RESOURCE: location_visits_poller_state.json | ||
KINESIS_BATCH_SIZE: 500 | ||
MAX_RETRIES: 3 | ||
ENCRYPTED_VARIABLES: | ||
REDSHIFT_DB_HOST: AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAKIwgZ8GCSqGSIb3DQEHBqCBkTCBjgIBADCBiAYJKoZIhvcNAQcBMB4GCWCGSAFlAwQBLjARBAzfC7it2NYa1YnFy+4CARCAW1NrqGfSfPptEF4epEXl8Hr6ntrJcZ0DE1GeGt2c2mMnMt7hcim39NTgxHvi5DIldF4J2UJzgG0KBs5UGRU9dyjrQu5zLfdB8Kv50d1lHfvqM2aDQAK0SQ188BY= | ||
REDSHIFT_DB_USER: AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAG0wawYJKoZIhvcNAQcGoF4wXAIBADBXBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDDqSUOKwGRhPNnJwhQIBEIAqJ/XgIWvG3fz4FnBPSzL640Apqd6SeIJ+KoU5N6Ka9RjN9eyBSBtU+WZJ | ||
REDSHIFT_DB_PASSWORD: AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAGswaQYJKoZIhvcNAQcGoFwwWgIBADBVBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDI90LTVkj0mhVM9dKgIBEIAoAV0TJogqQmNrh7BohDJ9hS7h4oKPcQy3z8kIRoW4Fltz3/zAP0HDew== | ||
SHOPPERTRAK_USERNAME: AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAGUwYwYJKoZIhvcNAQcGoFYwVAIBADBPBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDMwZFr7dqHccVpGsIgIBEIAigggkYIMh62vSRtwzJWr5Q0FGN5rX29BeCX/JcP1uHV7Jtw== | ||
SHOPPERTRAK_PASSWORD: AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAGswaQYJKoZIhvcNAQcGoFwwWgIBADBVBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDO0tpI+96T7sLWve0QIBEIAoq3KNN5xKl69tvlBReWIegDOru/Ejk1yxRwCoEd3f/J4A8FLm+vfVng== | ||
KINESIS_STREAM_ARN: AQECAHh7ea2tyZ6phZgT4B9BDKwguhlFtRC6hgt+7HbmeFsrsgAAAKkwgaYGCSqGSIb3DQEHBqCBmDCBlQIBADCBjwYJKoZIhvcNAQcBMB4GCWCGSAFlAwQBLjARBAzK/AO63EjbacrBSckCARCAYnWDJG+KL514QqwqguhZ7PTrA/NXbD9n9e41gNXF3qnxmHD4UHN5pGCzalRsPnyNanz6N0Up0LsvPKKkCFJb5F7Zqh9XroXKPRNs1DRTPmHqgtLyTPgJ88LnGUTzUrIDTqmi | ||
... |
This file contains 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,54 @@ | ||
_REDSHIFT_HOURS_QUERY = """ | ||
SELECT sierra_code, weekday, regular_open, regular_close | ||
FROM {hours_table} LEFT JOIN {codes_table} | ||
ON {hours_table}.drupal_location_id = {codes_table}.drupal_code | ||
WHERE date_of_change IS NULL;""" | ||
|
||
_REDSHIFT_CREATE_TABLE_QUERY = """ | ||
CREATE TEMPORARY TABLE #recoverable_site_dates AS | ||
SELECT shoppertrak_site_id, increment_start::DATE AS increment_date | ||
FROM {table} | ||
WHERE NOT is_healthy_data | ||
AND is_fresh | ||
AND increment_start >= '{start_date}' | ||
AND increment_start < '{end_date}' | ||
GROUP BY shoppertrak_site_id, increment_date;""" | ||
|
||
_REDSHIFT_KNOWN_QUERY = """ | ||
SELECT #recoverable_site_dates.shoppertrak_site_id, orbit, increment_start, | ||
id, is_healthy_data, enters, exits | ||
FROM #recoverable_site_dates LEFT JOIN {table} | ||
ON #recoverable_site_dates.shoppertrak_site_id = {table}.shoppertrak_site_id | ||
AND #recoverable_site_dates.increment_date = {table}.increment_start::DATE | ||
WHERE is_fresh;""" | ||
|
||
_REDSHIFT_UPDATE_QUERY = """ | ||
UPDATE {table} SET is_fresh = False | ||
WHERE id IN ({ids});""" | ||
|
||
REDSHIFT_DROP_QUERY = "DROP TABLE #recoverable_site_dates;" | ||
|
||
REDSHIFT_RECOVERABLE_QUERY = """ | ||
SELECT * | ||
FROM #recoverable_site_dates | ||
ORDER BY increment_date, shoppertrak_site_id;""" | ||
|
||
|
||
def build_redshift_hours_query(hours_table, codes_table): | ||
return _REDSHIFT_HOURS_QUERY.format( | ||
hours_table=hours_table, codes_table=codes_table | ||
) | ||
|
||
|
||
def build_redshift_create_table_query(table, start_date, end_date): | ||
return _REDSHIFT_CREATE_TABLE_QUERY.format( | ||
table=table, start_date=start_date, end_date=end_date | ||
) | ||
|
||
|
||
def build_redshift_known_query(table): | ||
return _REDSHIFT_KNOWN_QUERY.format(table=table) | ||
|
||
|
||
def build_redshift_update_query(table, ids): | ||
return _REDSHIFT_UPDATE_QUERY.format(table=table, ids=ids) |
This file contains 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.