Skip to content

fix: modernize background app #572

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion background/app/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
# limitations under the License.

# [START getting_started_background_config]
runtime: python37
runtime: python312
# [END getting_started_background_config]
12 changes: 4 additions & 8 deletions background/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@
to_language = request.form.get("lang", "")

if source_string == "":
error_message = "Empty value"
return error_message, 400
return f"Invalid request, you must provide a value.", 400

if to_language not in ACCEPTABLE_LANGUAGES:
error_message = "Unsupported language: {}".format(to_language)
return error_message, 400
return f"Unsupported language: {to_language}", 400

message = {
"Original": source_string,
Expand All @@ -78,11 +76,9 @@
"OriginalLanguage": "",
}

topic_name = "projects/{}/topics/{}".format(
os.getenv("GOOGLE_CLOUD_PROJECT"), "translate"
)
topic_name = f"projects/{os.getenv('GOOGLE_CLOUD_PROJECT')}/topics/translate"
publisher.publish(
topic=topic_name, data=json.dumps(message).encode("utf8")
topic=topic_name, data=json.dumps(message).encode("utf-8")
)
return redirect("/")

Expand Down
6 changes: 3 additions & 3 deletions background/app/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
google-cloud-firestore==2.11.1
google-cloud-pubsub==2.16.1
flask==2.2.5
google-cloud-firestore==2.18.0
google-cloud-pubsub==2.23.0
flask==3.0.3