Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: wait time and exception checks #8286

Merged
merged 2 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def get(self, environ, photo_key):
# GAE sets it to a guessed type if the header is not set.
response["Content-Type"] = None
return response


# [END gae_blobstore_handler_django]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def view_photo(photo_key):
def upload_photo():
"""Upload handler called by blobstore when a blob is uploaded in the test."""
return PhotoUploadHandler().post()


# [END gae_blobstore_handler_flask]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ def custom_deferred():
print("Executing deferred task.")
# request.environ contains the WSGI `environ` dictionary (See PEP 0333)
return deferred.Handler().post(request.environ)


# [END gae_deferred_handler_flask]
23 changes: 17 additions & 6 deletions appengine/standard_python3/bundled-services/mail/django/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,19 @@ def send_mail(address, body):
if address is None:
return HttpResponse(content="Error: Missing email address", status=400)

mail.send_mail(
sender=f"demo-app@{project_id}.appspotmail.com",
to=address,
subject="App Engine Outgoing Email",
body=body,
)
try:
mail.send_mail(
sender=f"demo-app@{project_id}.appspotmail.com",
to=address,
subject="App Engine Outgoing Email",
body=body,
)
except Exception as e:
print(f"Sending mail to {address} failed with exception {e}.")
return HttpResponse(
content=f"Exception {e} when sending mail to {address}.",
status=500,
)

print(f"Successfully sent mail to {address}.")
return HttpResponse(content=f"Successfully sent mail to {address}.", status=201)
Expand All @@ -79,6 +86,8 @@ def receive_mail(request):
break

return HttpResponse("OK")


# [END gae_mail_handler_receive_django]


Expand All @@ -91,6 +100,8 @@ def receive_bounce(request):
print(f"Bounce notification: {bounce_message.notification}")

return HttpResponse("OK")


# [END gae_mail_handler_bounce_django]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_send_receive(version):
assert "Successfully sent mail" in response.text

# Give the mail some time to be delivered and logs to post
time.sleep(30)
time.sleep(60)

# Fetch logs to check messages on received mail
entries = gcloud_cli(
Expand Down
20 changes: 14 additions & 6 deletions appengine/standard_python3/bundled-services/mail/flask/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ def send_mail():
print("Error: missing email address")
return "Error: Missing email address", 400

mail.send_mail(
sender=f"demo-app@{project_id}.appspotmail.com",
to=address,
subject="App Engine Outgoing Email",
body=request.form.get("body"),
)
try:
mail.send_mail(
sender=f"demo-app@{project_id}.appspotmail.com",
to=address,
subject="App Engine Outgoing Email",
body=request.form.get("body"),
)
except Exception as e:
print(f"Sending mail to {address} failed with exception {e}.")
return f"Exception {e} when sending mail to {address}.", 500

print(f"Successfully sent mail to {address}.")
return f"Successfully sent mail to {address}.", 201
Expand All @@ -77,6 +81,8 @@ def receive_bounce():
print("Bounce notification: ", bounce_message.notification)

return "OK", 200


# [END gae_mail_handler_bounce_flask]


Expand All @@ -92,4 +98,6 @@ def receive_mail(path):
break

return "OK", 200


# [END gae_mail_handler_receive_flask]
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_send_receive(version):
assert "Successfully sent mail" in response.text

# Give the mail some time to be delivered and logs to post
time.sleep(30)
time.sleep(60)

# Fetch logs to check messages on received mail
entries = gcloud_cli(
Expand Down
21 changes: 15 additions & 6 deletions appengine/standard_python3/bundled-services/mail/wsgi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def HelloReceiver(environ, start_response):
response = http.HTTPStatus.OK
start_response(f"{response.value} {response.phrase}", [])
return ["success".encode("utf-8")]


# [END gae_mail_handler_receive_wsgi]


Expand All @@ -54,6 +56,8 @@ def BounceReceiver(environ, start_response):
response = http.HTTPStatus.OK
start_response(f"{response.value} {response.phrase}", [])
return ["success".encode("utf-8")]


# [END gae_mail_handler_bounce_wsgi]


Expand Down Expand Up @@ -90,12 +94,17 @@ def HomePage(environ, start_response):
print("Error: missing email address")
return "Error: Missing email address", 400

mail.send_mail(
sender=f"demo-app@{project_id}.appspotmail.com",
to=address,
subject="App Engine Outgoing Email",
body=form.get("body")[0],
)
try:
mail.send_mail(
sender=f"demo-app@{project_id}.appspotmail.com",
to=address,
subject="App Engine Outgoing Email",
body=form.get("body")[0],
)
except Exception as e:
print(f"Sending mail to {address} failed with exception {e}.")
start_response("500 SERVER ERROR")
return [f"Exception {e} when sending mail to {address}.".encode("utf-8")]

print(f"Successfully sent mail to {address}.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_send_receive(version):
assert "Successfully sent mail" in response.text

# Give the mail some time to be delivered and logs to post
time.sleep(30)
time.sleep(60)

# Fetch logs to check messages on received mail
entries = gcloud_cli(
Expand Down