-
-
Notifications
You must be signed in to change notification settings - Fork 199
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 #936 from sabeechen/heroku
Add another instance of the addon token server to heroku
- Loading branch information
Showing
7 changed files
with
103 additions
and
18 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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
{ | ||
"build": { "dockerfile": "Dockerfile" }, | ||
"runArgs": ["--init", "--privileged"], | ||
"extensions": ["ms-python.python", "wholroyd.jinja","ms-python.vscode-pylance"], | ||
"forwardPorts": [3000] | ||
"forwardPorts": [3000], | ||
"mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ] | ||
} |
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,57 @@ | ||
import argparse | ||
from google.cloud import firestore | ||
from datetime import datetime, timedelta | ||
DELETE_BATCH_SIZE = 200 | ||
STORE_NAME = "error_reports" | ||
|
||
|
||
def delete_old_data(): | ||
# Initialize Firestore | ||
db = firestore.Client() | ||
collection_ref = db.collection(STORE_NAME) | ||
|
||
# Define the datetime for one week ago | ||
week_ago = datetime.now() - timedelta(days=7) | ||
|
||
# Query to find all documents older than a week | ||
total_deleted = 0 | ||
while True: | ||
to_delete = 0 | ||
batch = db.batch() | ||
docs = collection_ref.where('server_time', '<', week_ago).stream() | ||
for doc in docs: | ||
to_delete += 1 | ||
batch.delete(doc.reference) | ||
if to_delete >= DELETE_BATCH_SIZE: | ||
break | ||
if to_delete > 0: | ||
batch.commit() | ||
total_deleted += to_delete | ||
print(f"Deleted {to_delete} documents ({total_deleted} total)") | ||
else: | ||
break | ||
print(f"Success: All documents older than a week deleted ({total_deleted} total)") | ||
|
||
|
||
def main(): | ||
# Create command line argument parser | ||
parser = argparse.ArgumentParser() | ||
|
||
# Add purge argument | ||
parser.add_argument("--purge", help="Delete all documents older than a week.", action="store_true") | ||
|
||
# Add any other argument you want in future. For example: | ||
# parser.add_argument("--future_arg", help="Perform some future operation.") | ||
|
||
args = parser.parse_args() | ||
|
||
# Respond to arguments | ||
if args.purge: | ||
confirm = input('Are you sure you want to delete all documents older than a week? (y/n): ') | ||
if confirm.lower() == 'y': | ||
delete_old_data() | ||
else: | ||
print("Abort: No documents were deleted.") | ||
|
||
if __name__ == "__main__": | ||
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
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,3 @@ | ||
build: | ||
docker: | ||
web: hassio-google-drive-backup/Dockerfile-server |