Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9b3ff82

Browse filesBrowse files
author
Ace Nassri
authored
Address Andrew's prior comments (GoogleCloudPlatform#1623)
Change-Id: I8585d37ea6e17f33c554ede550fe171be11ed0e2
1 parent 635150e commit 9b3ff82
Copy full SHA for 9b3ff82

File tree

Expand file treeCollapse file tree

3 files changed

+15
-9
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+15
-9
lines changed

‎functions/concepts/main.py

Copy file name to clipboardExpand all lines: functions/concepts/main.py
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ def statelessness(request):
4040
# [END functions_concepts_stateless]
4141

4242

43+
# Placeholder
4344
def heavy_computation():
4445
return time.time()
4546

4647

48+
# Placeholder
4749
def light_computation():
4850
return time.time()
4951

@@ -101,7 +103,8 @@ def timeout(request):
101103
time.sleep(120)
102104

103105
# May not execute if function's timeout is <2 minutes
104-
return 'Done!'
106+
print('Function completed!')
107+
return 'Function completed!'
105108
# [END functions_concepts_after_timeout]
106109

107110

‎functions/tips/main.py

Copy file name to clipboardExpand all lines: functions/tips/main.py
+10-7Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
# [END functions_tips_connection_pooling]
2626

2727

28+
# Placeholder
2829
def file_wide_computation():
29-
return sum(range(10))
30+
return 1
3031

3132

33+
# Placeholder
3234
def function_specific_computation():
33-
return sum(range(10))
35+
return 1
3436

3537

3638
# [START functions_tips_lazy_globals]
@@ -105,7 +107,8 @@ def avoid_infinite_retries(data, context):
105107
event_age = (datetime.now() - event_time).total_seconds() * 1000
106108

107109
# Ignore events that are too old
108-
if event_age > 10000:
110+
max_age_ms = 10000
111+
if event_age > max_age_ms:
109112
print('Dropped {} (age {}ms)'.format(context.event_id, event_age))
110113
return 'Timeout'
111114

@@ -135,11 +138,11 @@ def retry_or_not(data, context):
135138
try_again = False
136139

137140
try:
138-
raise Exception('I failed you')
139-
except Exception as e:
141+
raise RuntimeError('I failed you')
142+
except RuntimeError:
140143
error_client.report_exception()
141144
if try_again:
142-
raise e # Raise the exception and try again
145+
raise # Raise the exception and try again
143146
else:
144-
return # Swallow the exception and don't retry
147+
pass # Swallow the exception and don't retry
145148
# [END functions_tips_retry]

‎functions/tips/main_test.py

Copy file name to clipboardExpand all lines: functions/tips/main_test.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_retry_or_not():
8484
assert error_client.report_exception.call_count == 1
8585

8686
event.data = {'retry': True}
87-
with pytest.raises(Exception):
87+
with pytest.raises(RuntimeError):
8888
main.retry_or_not(event, None)
8989

9090
assert error_client.report_exception.call_count == 2

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.