-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: switch download request to be async with firestore push updates
Closes #599
- Loading branch information
Showing
31 changed files
with
1,371 additions
and
971 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
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
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
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,81 @@ | ||
""" | ||
A module for interacting with firestore | ||
""" | ||
from os import environ | ||
from uuid import uuid4 | ||
|
||
from google.cloud import firestore | ||
|
||
project = None | ||
if environ.get("FLASK_DEBUG") == "1": | ||
#: setting the GOOGLE_CLOUD_PROJECT env var, causes gcloud to attempt to reauth | ||
project = "ut-dts-agrc-deq-enviro-dev" | ||
|
||
client = firestore.Client(project) | ||
|
||
""" | ||
Job document structure: | ||
{ | ||
"id": "string", | ||
"created": "timestamp", | ||
"updated": "timestamp", | ||
"status": "processing|complete|failed", | ||
"format": "csv|excel|filegdb|geojson|shapefile", | ||
"layers": { | ||
"tableName": { | ||
"processed": "boolean", | ||
"error": "string" | ||
} | ||
}, | ||
"error": "string", | ||
} | ||
""" | ||
|
||
|
||
def create_job(layers, format): | ||
""" | ||
Creates a job document in firestore. | ||
""" | ||
id = uuid4().hex | ||
|
||
doc_ref = client.collection("jobs").document(id) | ||
doc_ref.set( | ||
{ | ||
"id": id, | ||
"created": firestore.SERVER_TIMESTAMP, | ||
"updated": firestore.SERVER_TIMESTAMP, | ||
"status": "processing", | ||
"format": format, | ||
"layers": {layer: {"error": None, "processed": False} for layer in layers}, | ||
} | ||
) | ||
|
||
return id | ||
|
||
|
||
def update_job_status(id, status, error=None): | ||
""" | ||
Updates a job document in firestore. | ||
""" | ||
doc_ref = client.collection("jobs").document(id) | ||
doc_ref.update( | ||
{ | ||
"updated": firestore.SERVER_TIMESTAMP, | ||
"status": status, | ||
"error": error, | ||
} | ||
) | ||
|
||
|
||
def update_job_layer(id, layer, processed, error=None): | ||
""" | ||
Updates a job document in firestore. | ||
""" | ||
doc_ref = client.collection("jobs").document(id) | ||
doc_ref.update( | ||
{ | ||
"updated": firestore.SERVER_TIMESTAMP, | ||
f"layers.{layer}.processed": processed, | ||
f"layers.{layer}.error": error, | ||
} | ||
) |
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
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,17 @@ | ||
rules_version = '2'; | ||
|
||
service cloud.firestore { | ||
match /databases/{database}/documents { | ||
match /{document=**} { | ||
allow read: if true; | ||
} | ||
} | ||
} | ||
|
||
service firebase.storage { | ||
match /b/{bucket}/o { | ||
match /{allPaths=**} { | ||
allow read: if true; | ||
} | ||
} | ||
} |
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 @@ | ||
{ | ||
"indexes": [], | ||
"fieldOverrides": [] | ||
} |
Oops, something went wrong.