-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 #4319 from google/rc_2020_9
Rc 2020 9
- Loading branch information
Showing
395 changed files
with
20,361 additions
and
16,685 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 was deleted.
Oops, something went wrong.
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,69 @@ | ||
"""Blockly Demo: Add timestamps | ||
Copyright 2020 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
"""A script to get all Xml entries in the datastore for Blockly demos | ||
and reinsert any that do not have a last_accessed time. | ||
This script should only need to be run once, but may take a long time | ||
to complete. | ||
NDB does not provide a way to query for all entities that are missing a | ||
given property, so we have to get all of them and discard any that | ||
already have a last_accessed time. | ||
Auth: `gcloud auth login` | ||
Set the correct project: `gcloud config set project blockly-demo` | ||
See the current project: `gcloud config get-value project` | ||
Start a venv: `python3 -m venv venv && source venv/bin/activate` | ||
Inside your vm run `pip install google-cloud-ndb` | ||
Run the script: `python add_timestamps.py` | ||
""" | ||
|
||
__author__ = "[email protected] (Rachel Fenichel)" | ||
|
||
|
||
from google.cloud import ndb | ||
from storage import Xml | ||
import datetime | ||
|
||
PAGE_SIZE = 1000 | ||
|
||
def handle_results(results): | ||
for x in results: | ||
if (x.last_accessed is None): | ||
x.put() | ||
|
||
def run_query(): | ||
client = ndb.Client() | ||
with client.context(): | ||
query = Xml.query() | ||
print(f'Total entries: {query.count()}') | ||
cursor = None | ||
more = True | ||
page_count = 0 | ||
result_count = 0 | ||
while more: | ||
results, cursor, more = query.fetch_page(PAGE_SIZE, start_cursor=cursor) | ||
handle_results(results) | ||
page_count = page_count + 1 | ||
result_count = result_count + len(results) | ||
print(f'{datetime.datetime.now().strftime("%I:%M:%S %p")} : page {page_count} : {result_count}') | ||
|
||
run_query() |
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,51 @@ | ||
""" | ||
Copyright 2020 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
"""Delete expired XML. | ||
""" | ||
|
||
__author__ = "[email protected] (Rachel Fenichel)" | ||
|
||
|
||
import storage | ||
import datetime | ||
|
||
from google.cloud import ndb | ||
|
||
|
||
EXPIRATION_DAYS = 365 | ||
# Limit the query to avoid timeouts. | ||
QUERY_LIMIT = 1000 | ||
|
||
def delete_expired(): | ||
"""Deletes entries that have not been accessed in more than a year.""" | ||
bestBefore = datetime.datetime.utcnow() - datetime.timedelta(days=EXPIRATION_DAYS) | ||
client = ndb.Client() | ||
with client.context(): | ||
query = storage.Xml.query(storage.Xml.last_accessed < bestBefore) | ||
results = query.fetch(limit=QUERY_LIMIT, keys_only=True) | ||
for x in results: | ||
x.delete() | ||
|
||
|
||
def app(environ, start_response): | ||
out = "" | ||
headers = [ | ||
("Content-Type", "text/plain") | ||
] | ||
start_response("200 OK", headers) | ||
delete_expired() | ||
return [out.encode("utf-8")] |
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
Oops, something went wrong.