Skip to content

Commit e118431

Browse files
author
Ace Nassri
authored
Address Stewart's comments (GoogleCloudPlatform#1591)
* Address Stewart's comments * Fix incorrect comments Change-Id: Id393e074866ca12e84fa2ccaf43e4a4b25f9a0c9 * Fix lint Change-Id: Ib2ef96d76573392af62e6ccb151b844787d9246b
1 parent e00ab29 commit e118431

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

functions/helloworld/main.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def hello_background(data, context):
3636
Args:
3737
data (dict): The dictionary with data specific to the given event.
3838
context (google.cloud.functions.Context): The Cloud Functions event
39-
context.
39+
metadata.
4040
"""
4141
if data and 'name' in data:
4242
name = data['name']
@@ -72,7 +72,7 @@ def hello_pubsub(data, context):
7272
Args:
7373
data (dict): The dictionary with data specific to this type of event.
7474
context (google.cloud.functions.Context): The Cloud Functions event
75-
context.
75+
metadata.
7676
"""
7777
import base64
7878

@@ -90,7 +90,7 @@ def hello_gcs(data, context):
9090
Args:
9191
data (dict): The dictionary with data specific to this type of event.
9292
context (google.cloud.functions.Context): The Cloud Functions
93-
event context.
93+
event metadata.
9494
"""
9595
print("File: {}.".format(data['objectId']))
9696
# [END functions_helloworld_storage]
@@ -162,8 +162,7 @@ def hello_error_2(request):
162162
logging.error(RuntimeError('I failed you (logging.error)'))
163163
sys.stderr.write('I failed you (sys.stderr.write)\n')
164164

165-
# WILL NOT be reported to Stackdriver Error Reporting, but will show up
166-
# in request logs (as a 500 response)
165+
# This WILL be reported to Stackdriver Error Reporting
167166
from flask import abort
168167
return abort(500)
169168
# [END functions_helloworld_error]

functions/tips/main.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,18 @@ def connection_pooling(request):
8888

8989

9090
# [START functions_tips_infinite_retries]
91-
def avoid_infinite_retries(event, context):
92-
timestamp = event.timestamp
91+
def avoid_infinite_retries(data, context):
92+
"""Background Cloud Function that only executes within a certain
93+
time period after the triggering event.
94+
95+
Args:
96+
data (dict): The event payload.
97+
context (google.cloud.functions.Context): The event metadata.
98+
Returns:
99+
None; output is written to Stackdriver Logging
100+
"""
101+
102+
timestamp = data.timestamp
93103

94104
event_time = parser.parse(timestamp)
95105
event_age = (datetime.now() - event_time).total_seconds() * 1000
@@ -106,11 +116,20 @@ def avoid_infinite_retries(event, context):
106116

107117

108118
# [START functions_tips_retry]
109-
def retry_or_not(event, context):
119+
def retry_or_not(data, context):
120+
"""Background Cloud Function that demonstrates how to toggle retries.
121+
122+
Args:
123+
data (dict): The event payload.
124+
context (google.cloud.functions.Context): The event metadata.
125+
Returns:
126+
None; output is written to Stackdriver Logging
127+
"""
128+
110129
from google import cloud
111130
error_client = cloud.error_reporting.Client()
112131

113-
if event.data.get('retry'):
132+
if data.data.get('retry'):
114133
try_again = True
115134
else:
116135
try_again = False

0 commit comments

Comments
 (0)