Skip to content

Commit 6919982

Browse files
committed
mod19 fixes to support Py2
1 parent f551864 commit 6919982

File tree

4 files changed

+66
-10
lines changed

4 files changed

+66
-10
lines changed

mod19-pubsub/app.yaml

+14-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
runtime: python310
15+
#runtime: python310
16+
runtime: python27
17+
threadsafe: yes
18+
api_version: 1
19+
20+
handlers:
21+
- url: /.*
22+
script: main.app
23+
24+
libraries:
25+
- name: setuptools
26+
version: latest
27+
- name: grpcio
28+
version: latest

mod19-pubsub/app3.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
runtime: python310

mod19-pubsub/appengine_config.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import pkg_resources
16+
from google.appengine.ext import vendor
17+
18+
# Set PATH to your libraries folder.
19+
PATH = 'lib'
20+
# Add libraries installed in the PATH folder.
21+
vendor.add(PATH)
22+
# Add libraries to pkg_resources working set to find the distribution.
23+
pkg_resources.working_set.add_entry(PATH)

mod19-pubsub/main.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,20 @@ def log_visitors():
6363
# tally recent visitor counts from queue then delete those tasks
6464
tallies = {}
6565
acks = set()
66-
with psc_client:
67-
rsp = psc_client.pull(subscription=SUB_PATH, max_messages=TASKS)
68-
msgs = rsp.received_messages
69-
for rcvd_msg in msgs:
70-
acks.add(rcvd_msg.ack_id)
71-
visitor = rcvd_msg.message.data.decode('utf-8')
72-
tallies[visitor] = tallies.get(visitor, 0) + 1
73-
if acks:
74-
psc_client.acknowledge(subscription=SUB_PATH, ack_ids=acks)
66+
#with psc_client:
67+
rsp = psc_client.pull(subscription=SUB_PATH, max_messages=TASKS)
68+
msgs = rsp.received_messages
69+
for rcvd_msg in msgs:
70+
acks.add(rcvd_msg.ack_id)
71+
visitor = rcvd_msg.message.data.decode('utf-8')
72+
tallies[visitor] = tallies.get(visitor, 0) + 1
73+
if acks:
74+
psc_client.acknowledge(subscription=SUB_PATH, ack_ids=acks)
75+
if hasattr(psc_client, 'close'):
76+
try:
77+
psc_client.close()
78+
except AttributeError:
79+
pass
7580

7681
# increment those counts in Datastore and return
7782
if tallies:

0 commit comments

Comments
 (0)