diff --git a/appengine/flexible_python37_and_earlier/tasks/Dockerfile b/appengine/flexible_python37_and_earlier/tasks/Dockerfile deleted file mode 100644 index 5aaeb51144d..00000000000 --- a/appengine/flexible_python37_and_earlier/tasks/Dockerfile +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright 2021 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Use the official Python image. -# https://hub.docker.com/_/python -FROM python:3.11 - -# Copy local code to the container image. -ENV APP_HOME /app -WORKDIR $APP_HOME -COPY . . - -# Install production dependencies. -RUN pip install Flask gunicorn - -# Run the web service on container startup. Here we use the gunicorn -# webserver, with one worker process and 8 threads. -# For environments with multiple CPU cores, increase the number of workers -# to be equal to the cores available. -CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 main:app diff --git a/appengine/flexible_python37_and_earlier/tasks/README.md b/appengine/flexible_python37_and_earlier/tasks/README.md deleted file mode 100644 index 5eb60d5fa45..00000000000 --- a/appengine/flexible_python37_and_earlier/tasks/README.md +++ /dev/null @@ -1,122 +0,0 @@ -# Google Cloud Tasks Samples - -[![Open in Cloud Shell][shell_img]][shell_link] - -[shell_img]: http://gstatic.com/cloudssh/images/open-btn.png -[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=appengine/flexible_python37_and_earlier/tasks/README.md - -Sample command-line programs for interacting with the Cloud Tasks API -. - -App Engine queues push tasks to an App Engine HTTP target. This directory -contains both the App Engine app to deploy, as well as the snippets to run -locally to push tasks to it, which could also be called on App Engine. - -`create_app_engine_queue_task.py` is a simple command-line program to create -tasks to be pushed to the App Engine app. - -`main.py` is the main App Engine app. This app serves as an endpoint to receive -App Engine task attempts. - -`app.yaml` configures the App Engine app. - - -## Prerequisites to run locally: - -Please refer to [Setting Up a Python Development Environment](https://cloud.google.com/python/setup). - -### Authentication - -To set up authentication, please refer to our -[authentication getting started guide](https://cloud.google.com/docs/authentication/getting-started). - -### Install Dependencies - -To install the dependencies for this sample, use the following command: - -```sh -pip install -r requirements.txt -``` - -This sample uses the common protos in the [googleapis](https://github.com/googleapis/googleapis) -repository. For more info, see -[Protocol Buffer Basics](https://developers.google.com/protocol-buffers/docs/pythontutorial). - -## Deploying the App Engine App - -Deploy the App Engine app with gcloud: - -* To deploy to the Standard environment: - ```sh - gcloud app deploy app.yaml - ``` -* To deploy to the Flexible environment: - ```sh - gcloud app deploy app.flexible.yaml - ``` - -Verify the index page is serving: - -```sh -gcloud app browse -``` - -The App Engine app serves as a target for the push requests. It has an -endpoint `/example_task_handler` that reads the payload (i.e., the request body) -of the HTTP POST request and logs it. The log output can be viewed with: - -```sh -gcloud app logs read -``` - -## Creating a queue - -To create a queue using the Cloud SDK, use the following gcloud command: - -```sh -gcloud tasks queues create my-appengine-queue -``` - -Note: A newly created queue will route to the default App Engine service and -version unless configured to do otherwise. - -## Run the Sample Using the Command Line - -Set environment variables: - -First, your project ID: - -```sh -export PROJECT_ID=my-project-id -``` - -Then the queue ID, as specified at queue creation time. Queue IDs already -created can be listed with `gcloud tasks queues list`. - -```sh -export QUEUE_ID=my-appengine-queue -``` - -And finally the location ID, which can be discovered with -`gcloud tasks queues describe $QUEUE_ID`, with the location embedded in -the "name" value (for instance, if the name is -"projects/my-project/locations/us-central1/queues/my-appengine-queue", then the -location is "us-central1"). - -```sh -export LOCATION_ID=us-central1 -``` - -### Using App Engine Queues - -Running the sample will create a task, targeted at the `/example_task_handler` -endpoint, with a payload specified: - -> **Note** -> Please update -> [create_app_engine_queue_task.py](./create_app_engine_queue_task.py) before running the following -> command. - -```sh -python create_app_engine_queue_task.py --project=$PROJECT_ID --queue=$QUEUE_ID --location=$LOCATION_ID --payload=hello -``` diff --git a/appengine/flexible_python37_and_earlier/tasks/app.flexible.yaml b/appengine/flexible_python37_and_earlier/tasks/app.flexible.yaml deleted file mode 100644 index 5b3b333fda6..00000000000 --- a/appengine/flexible_python37_and_earlier/tasks/app.flexible.yaml +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2019 Google LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -runtime: python -env: flex -entrypoint: gunicorn -b :$PORT --threads=4 main:app - -runtime_config: - python_version: 3 diff --git a/appengine/flexible_python37_and_earlier/tasks/app.yaml b/appengine/flexible_python37_and_earlier/tasks/app.yaml deleted file mode 100644 index 15ac0d97205..00000000000 --- a/appengine/flexible_python37_and_earlier/tasks/app.yaml +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2019 Google LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -runtime: python37 diff --git a/appengine/flexible_python37_and_earlier/tasks/create_app_engine_queue_task.py b/appengine/flexible_python37_and_earlier/tasks/create_app_engine_queue_task.py deleted file mode 100644 index 7ddb6fb5a69..00000000000 --- a/appengine/flexible_python37_and_earlier/tasks/create_app_engine_queue_task.py +++ /dev/null @@ -1,121 +0,0 @@ -# Copyright 2019 Google LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - - -import argparse - - -def create_task(project, queue, location, payload=None, in_seconds=None): - # [START cloud_tasks_appengine_create_task] - """Create a task for a given queue with an arbitrary payload.""" - - from google.cloud import tasks_v2 - from google.protobuf import timestamp_pb2 - import datetime - import json - - # Create a client. - client = tasks_v2.CloudTasksClient() - - # TODO(developer): Uncomment these lines and replace with your values. - # project = 'my-project-id' - # queue = 'my-appengine-queue' - # location = 'us-central1' - # payload = 'hello' or {'param': 'value'} for application/json - # in_seconds = None - - # Construct the fully qualified queue name. - parent = client.queue_path(project, location, queue) - - # Construct the request body. - task = { - "app_engine_http_request": { # Specify the type of request. - "http_method": tasks_v2.HttpMethod.POST, - "relative_uri": "/example_task_handler", - } - } - if payload is not None: - if isinstance(payload, dict): - # Convert dict to JSON string - payload = json.dumps(payload) - # specify http content-type to application/json - task["app_engine_http_request"]["headers"] = { - "Content-type": "application/json" - } - # The API expects a payload of type bytes. - converted_payload = payload.encode() - - # Add the payload to the request. - task["app_engine_http_request"]["body"] = converted_payload - - if in_seconds is not None: - # Convert "seconds from now" into an rfc3339 datetime string. - d = datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta( - seconds=in_seconds - ) - - # Create Timestamp protobuf. - timestamp = timestamp_pb2.Timestamp() - timestamp.FromDatetime(d) - - # Add the timestamp to the tasks. - task["schedule_time"] = timestamp - - # Use the client to build and send the task. - response = client.create_task(parent=parent, task=task) - - print(f"Created task {response.name}") - return response - - -# [END cloud_tasks_appengine_create_task] - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description=create_task.__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter, - ) - - parser.add_argument( - "--project", - help="Project of the queue to add the task to.", - required=True, - ) - - parser.add_argument( - "--queue", - help="ID (short name) of the queue to add the task to.", - required=True, - ) - - parser.add_argument( - "--location", - help="Location of the queue to add the task to.", - required=True, - ) - - parser.add_argument( - "--payload", help="Optional payload to attach to the push queue." - ) - - parser.add_argument( - "--in_seconds", - type=int, - help="The number of seconds from now to schedule task attempt.", - ) - - args = parser.parse_args() - - create_task(args.project, args.queue, args.location, args.payload, args.in_seconds) diff --git a/appengine/flexible_python37_and_earlier/tasks/create_app_engine_queue_task_test.py b/appengine/flexible_python37_and_earlier/tasks/create_app_engine_queue_task_test.py deleted file mode 100644 index 3bacaed03ac..00000000000 --- a/appengine/flexible_python37_and_earlier/tasks/create_app_engine_queue_task_test.py +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2019 Google LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os - -import create_app_engine_queue_task - -TEST_PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") -TEST_LOCATION = os.getenv("TEST_QUEUE_LOCATION", "us-central1") -TEST_QUEUE_NAME = os.getenv("TEST_QUEUE_NAME", "my-appengine-queue") - - -def test_create_task(): - result = create_app_engine_queue_task.create_task( - TEST_PROJECT_ID, TEST_QUEUE_NAME, TEST_LOCATION - ) - assert TEST_QUEUE_NAME in result.name diff --git a/appengine/flexible_python37_and_earlier/tasks/main.py b/appengine/flexible_python37_and_earlier/tasks/main.py deleted file mode 100644 index 4cb9b84a0b6..00000000000 --- a/appengine/flexible_python37_and_earlier/tasks/main.py +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright 2019 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""App Engine app to serve as an endpoint for App Engine queue samples.""" - -# [START cloud_tasks_appengine_quickstart] -from flask import Flask, render_template, request - -app = Flask(__name__) - - -@app.route("/example_task_handler", methods=["POST"]) -def example_task_handler(): - """Log the request payload.""" - payload = request.get_data(as_text=True) or "(empty payload)" - print(f"Received task with payload: {payload}") - return render_template("index.html", payload=payload) - - -# [END cloud_tasks_appengine_quickstart] - - -@app.route("/") -def hello(): - """Basic index to verify app is serving.""" - return "Hello World!" - - -if __name__ == "__main__": - # This is used when running locally. Gunicorn is used to run the - # application on Google App Engine. See entrypoint in app.yaml. - app.run(host="127.0.0.1", port=8080, debug=True) diff --git a/appengine/flexible_python37_and_earlier/tasks/main_test.py b/appengine/flexible_python37_and_earlier/tasks/main_test.py deleted file mode 100644 index 42b96402dd0..00000000000 --- a/appengine/flexible_python37_and_earlier/tasks/main_test.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright 2019 Google LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import pytest - - -@pytest.fixture -def app(): - import main - - main.app.testing = True - return main.app.test_client() - - -def test_index(app): - r = app.get("/") - assert r.status_code == 200 - - -def test_log_payload(capsys, app): - payload = "test_payload" - - r = app.post("/example_task_handler", data=payload) - assert r.status_code == 200 - - out, _ = capsys.readouterr() - assert payload in out - - -def test_empty_payload(capsys, app): - r = app.post("/example_task_handler") - assert r.status_code == 200 - - out, _ = capsys.readouterr() - assert "empty payload" in out diff --git a/appengine/flexible_python37_and_earlier/tasks/noxfile_config.py b/appengine/flexible_python37_and_earlier/tasks/noxfile_config.py deleted file mode 100644 index 1665dd736f8..00000000000 --- a/appengine/flexible_python37_and_earlier/tasks/noxfile_config.py +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2023 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Default TEST_CONFIG_OVERRIDE for python repos. - -# You can copy this file into your directory, then it will be imported from -# the noxfile.py. - -# The source of truth: -# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py - -TEST_CONFIG_OVERRIDE = { - # You can opt out from the test for specific Python versions. - # Skipping for Python 3.9 due to pyarrow compilation failure. - "ignored_versions": ["2.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"], - # Old samples are opted out of enforcing Python type hints - # All new samples should feature them - "enforce_type_hints": False, - # An envvar key for determining the project id to use. Change it - # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a - # build specific Cloud project. You can also use your own string - # to use your own Cloud project. - "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", - # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - # A dictionary you want to inject into your test. Don't put any - # secrets here. These values will override predefined values. - "envs": {}, -} diff --git a/appengine/flexible_python37_and_earlier/tasks/requirements-test.txt b/appengine/flexible_python37_and_earlier/tasks/requirements-test.txt deleted file mode 100644 index 15d066af319..00000000000 --- a/appengine/flexible_python37_and_earlier/tasks/requirements-test.txt +++ /dev/null @@ -1 +0,0 @@ -pytest==8.2.0 diff --git a/appengine/flexible_python37_and_earlier/tasks/requirements.txt b/appengine/flexible_python37_and_earlier/tasks/requirements.txt deleted file mode 100644 index 93643e9fb2a..00000000000 --- a/appengine/flexible_python37_and_earlier/tasks/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -Flask==3.0.3; python_version > '3.6' -Flask==2.0.3; python_version < '3.7' -gunicorn==23.0.0 -google-cloud-tasks==2.18.0 -Werkzeug==3.0.3 diff --git a/appengine/flexible_python37_and_earlier/tasks/snippets_test.py b/appengine/flexible_python37_and_earlier/tasks/snippets_test.py deleted file mode 100644 index d0483389fc8..00000000000 --- a/appengine/flexible_python37_and_earlier/tasks/snippets_test.py +++ /dev/null @@ -1,130 +0,0 @@ -# Copyright 2019 Google LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import uuid - -import pytest - -import snippets - -TEST_PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT") -TEST_LOCATION = os.getenv("TEST_QUEUE_LOCATION", "us-central1") -QUEUE_NAME_1 = f"queue-{uuid.uuid4()}" -QUEUE_NAME_2 = f"queue-{uuid.uuid4()}" - - -@pytest.mark.order1 -def test_create_queue(): - name = "projects/{}/locations/{}/queues/{}".format( - TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_2 - ) - result = snippets.create_queue( - TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1, QUEUE_NAME_2 - ) - assert name in result.name - - -@pytest.mark.order2 -def test_update_queue(): - name = "projects/{}/locations/{}/queues/{}".format( - TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1 - ) - result = snippets.update_queue(TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1) - assert name in result.name - - -@pytest.mark.order3 -def test_create_task(): - name = "projects/{}/locations/{}/queues/{}".format( - TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1 - ) - result = snippets.create_task(TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1) - assert name in result.name - - -@pytest.mark.order4 -def test_create_task_with_data(): - name = "projects/{}/locations/{}/queues/{}".format( - TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1 - ) - result = snippets.create_tasks_with_data( - TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1 - ) - assert name in result.name - - -@pytest.mark.order5 -def test_create_task_with_name(): - name = "projects/{}/locations/{}/queues/{}".format( - TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1 - ) - result = snippets.create_task_with_name( - TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1, "foo" - ) - assert name in result.name - - -@pytest.mark.order6 -def test_delete_task(): - result = snippets.delete_task(TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1) - assert result is None - - -@pytest.mark.order7 -def test_purge_queue(): - name = "projects/{}/locations/{}/queues/{}".format( - TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1 - ) - result = snippets.purge_queue(TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1) - assert name in result.name - - -@pytest.mark.order8 -def test_pause_queue(): - name = "projects/{}/locations/{}/queues/{}".format( - TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1 - ) - result = snippets.pause_queue(TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1) - assert name in result.name - - -@pytest.mark.order9 -def test_delete_queue(): - result = snippets.delete_queue(TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_1) - assert result is None - - result = snippets.delete_queue(TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME_2) - assert result is None - - -@pytest.mark.order10 -def test_retry_task(): - QUEUE_SIZE = 3 - QUEUE_NAME = [] - for i in range(QUEUE_SIZE): - QUEUE_NAME.append(f"queue-{uuid.uuid4()}") - - name = "projects/{}/locations/{}/queues/{}".format( - TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME[2] - ) - result = snippets.retry_task( - TEST_PROJECT_ID, TEST_LOCATION, QUEUE_NAME[0], QUEUE_NAME[1], QUEUE_NAME[2] - ) - assert name in result.name - - for i in range(QUEUE_SIZE): - snippets.delete_queue( - project=TEST_PROJECT_ID, location=TEST_LOCATION, queue=QUEUE_NAME[i] - ) diff --git a/appengine/flexible_python37_and_earlier/tasks/templates/index.html b/appengine/flexible_python37_and_earlier/tasks/templates/index.html deleted file mode 100644 index 7e4efc7b336..00000000000 --- a/appengine/flexible_python37_and_earlier/tasks/templates/index.html +++ /dev/null @@ -1,21 +0,0 @@ - - - -
-Printed task payload: {{ payload }}
- - \ No newline at end of file