-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,240 additions
and
9 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
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,9 @@ | ||
[run] | ||
omit = | ||
*/test*/* | ||
*/helpers/* | ||
*/database_gen/* | ||
|
||
[report] | ||
exclude_lines = | ||
if __name__ == .__main__.: |
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,5 @@ | ||
# Environment variables for the reverse_geolocation functions | ||
FEEDS_DATABASE_URL=${{FEEDS_DATABASE_URL}} | ||
BUCKET_NAME=${{BUCKET_NAME}} | ||
MAX_RETRIES=${{MAX_RETRIES}} | ||
# TODO: add the other env variables here |
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,11 @@ | ||
# Reverse Geolocation | ||
|
||
## Function Workflow | ||
|
||
|
||
## Function Configuration | ||
|
||
|
||
## Local Development | ||
|
||
Local development of these functions should follow standard practices for GCP serverless functions. For general instructions on setting up the development environment, refer to the main [README.md](../README.md) file. |
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,20 @@ | ||
{ | ||
"name": "reverse-geolocation", | ||
"description": "Function to reverse geolocate coordinates", | ||
"entry_point": "reverse_geolocation", | ||
"timeout": 3600, | ||
"trigger_http": false, | ||
"include_folders": ["database_gen", "helpers"], | ||
"environment_variables": [], | ||
"secret_environment_variables": [ | ||
{ | ||
"key": "FEEDS_DATABASE_URL" | ||
} | ||
], | ||
"ingress_settings": "ALLOW_ALL", | ||
"max_instance_request_concurrency": 1, | ||
"max_instance_count": 10, | ||
"min_instance_count": 0, | ||
"available_cpu": 1, | ||
"available_memory": "4Gi" | ||
} |
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,29 @@ | ||
# Common packages | ||
functions-framework==3.* | ||
google-cloud-logging | ||
psycopg2-binary==2.9.6 | ||
aiohttp~=3.10.5 | ||
asyncio~=3.4.3 | ||
urllib3~=2.2.2 | ||
requests~=2.32.3 | ||
attrs~=23.1.0 | ||
pluggy~=1.3.0 | ||
certifi~=2024.7.4 | ||
|
||
# SQL Alchemy and Geo Alchemy | ||
SQLAlchemy==2.0.23 | ||
geoalchemy2==0.14.7 | ||
|
||
# Google specific packages for this function | ||
google-cloud-pubsub | ||
google-cloud-datastore | ||
google-cloud-storage | ||
google-cloud-bigquery | ||
cloudevents~=1.10.1 | ||
google-cloud-tasks | ||
google-cloud-storage | ||
|
||
# Additional packages for this function | ||
pycountry | ||
shapely | ||
gtfs-kit |
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,4 @@ | ||
Faker | ||
pytest~=7.4.3 | ||
urllib3-mock | ||
requests-mock |
Empty file.
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 @@ | ||
ERROR_STATUS_CODE = 299 # Custom status code to stop Cloud Tasks retries |
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,39 @@ | ||
import logging | ||
from typing import Dict, Tuple | ||
|
||
import flask | ||
import functions_framework | ||
from cloudevents.http import CloudEvent | ||
|
||
from reverse_geolocation_aggregator import reverse_geolocation_aggregate as aggregator | ||
from reverse_geolocation_processor import reverse_geolocation_process as processor | ||
from reverse_geolocator import reverse_geolocation as geolocator | ||
|
||
# Initialize logging | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
|
||
@functions_framework.cloud_event | ||
def reverse_geolocation(cloud_event: CloudEvent): | ||
"""Function that is triggered when a new dataset is uploaded to extract the location information.""" | ||
return geolocator(cloud_event) | ||
|
||
|
||
@functions_framework.http | ||
def reverse_geolocation_process( | ||
request: flask.Request, | ||
) -> Tuple[str, int] | Tuple[Dict, int]: | ||
""" | ||
Main function to handle reverse geolocation population. | ||
""" | ||
return processor(request) | ||
|
||
|
||
@functions_framework.http | ||
def reverse_geolocation_aggregate( | ||
request: flask.Request, | ||
) -> Tuple[str, int] | Tuple[Dict, int]: | ||
""" | ||
Main function to handle reverse geolocation population. | ||
""" | ||
return aggregator(request) |
Oops, something went wrong.