File tree Expand file tree Collapse file tree 3 files changed +15
-9
lines changed
Filter options
Expand file tree Collapse file tree 3 files changed +15
-9
lines changed
Original file line number Diff line number Diff line change @@ -40,10 +40,12 @@ def statelessness(request):
40
40
# [END functions_concepts_stateless]
41
41
42
42
43
+ # Placeholder
43
44
def heavy_computation ():
44
45
return time .time ()
45
46
46
47
48
+ # Placeholder
47
49
def light_computation ():
48
50
return time .time ()
49
51
@@ -101,7 +103,8 @@ def timeout(request):
101
103
time .sleep (120 )
102
104
103
105
# May not execute if function's timeout is <2 minutes
104
- return 'Done!'
106
+ print ('Function completed!' )
107
+ return 'Function completed!'
105
108
# [END functions_concepts_after_timeout]
106
109
107
110
Original file line number Diff line number Diff line change 25
25
# [END functions_tips_connection_pooling]
26
26
27
27
28
+ # Placeholder
28
29
def file_wide_computation ():
29
- return sum ( range ( 10 ))
30
+ return 1
30
31
31
32
33
+ # Placeholder
32
34
def function_specific_computation ():
33
- return sum ( range ( 10 ))
35
+ return 1
34
36
35
37
36
38
# [START functions_tips_lazy_globals]
@@ -105,7 +107,8 @@ def avoid_infinite_retries(data, context):
105
107
event_age = (datetime .now () - event_time ).total_seconds () * 1000
106
108
107
109
# Ignore events that are too old
108
- if event_age > 10000 :
110
+ max_age_ms = 10000
111
+ if event_age > max_age_ms :
109
112
print ('Dropped {} (age {}ms)' .format (context .event_id , event_age ))
110
113
return 'Timeout'
111
114
@@ -135,11 +138,11 @@ def retry_or_not(data, context):
135
138
try_again = False
136
139
137
140
try :
138
- raise Exception ('I failed you' )
139
- except Exception as e :
141
+ raise RuntimeError ('I failed you' )
142
+ except RuntimeError :
140
143
error_client .report_exception ()
141
144
if try_again :
142
- raise e # Raise the exception and try again
145
+ raise # Raise the exception and try again
143
146
else :
144
- return # Swallow the exception and don't retry
147
+ pass # Swallow the exception and don't retry
145
148
# [END functions_tips_retry]
Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ def test_retry_or_not():
84
84
assert error_client .report_exception .call_count == 1
85
85
86
86
event .data = {'retry' : True }
87
- with pytest .raises (Exception ):
87
+ with pytest .raises (RuntimeError ):
88
88
main .retry_or_not (event , None )
89
89
90
90
assert error_client .report_exception .call_count == 2
You can’t perform that action at this time.
0 commit comments