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

migrate code from googleapis/python-scheduler #9558

Merged
merged 91 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
968f972
Add Cloud Scheduler sample [(#1968)](https://github.com/GoogleCloudPl…
averikitsch Jul 24, 2019
b3ce5f8
Adds updates for samples profiler ... vision [(#2439)](https://github…
gguuss Oct 7, 2019
550c788
Auto-update dependencies. [(#2005)](https://github.com/GoogleCloudPla…
dpebot Dec 21, 2019
1fa2ad7
Simplify noxfile setup. [(#2806)](https://github.com/GoogleCloudPlatf…
kurtisvg Apr 2, 2020
1177245
update flask in scheduler [(#3403)](https://github.com/GoogleCloudPla…
leahecole Apr 14, 2020
ad74ad0
Update dependency google-cloud-scheduler to v1.3.0 [(#3840)](https://…
renovate-bot May 20, 2020
15cc301
Replace GCLOUD_PROJECT with GOOGLE_CLOUD_PROJECT. [(#4022)](https://g…
kurtisvg Jun 9, 2020
14f7dcb
chore(deps): update dependency pytest to v5.4.3 [(#4279)](https://git…
renovate-bot Jul 12, 2020
e5c8e09
Update dependency pytest to v6 [(#4390)](https://github.com/GoogleClo…
renovate-bot Aug 1, 2020
6570af1
chore: update templates
danoscarmike Aug 20, 2020
46f6805
feat!: migrate to microgenerator (#29)
danoscarmike Aug 27, 2020
f70f153
chore(deps): update dependency google-cloud-scheduler to v2 (#32)
renovate-bot Oct 16, 2020
9e60c5e
chore: update templates (#44)
yoshi-automation Dec 8, 2020
ce8c206
chore(deps): update dependency google-cloud-scheduler to v2.1.0 (#45)
renovate-bot Dec 9, 2020
16f8aa4
chore(deps): update dependency google-cloud-scheduler to v2.1.1 (#64)
renovate-bot Mar 5, 2021
06f4f7b
chore(deps): update dependency gunicorn to v20.1.0 (#69)
renovate-bot Mar 27, 2021
0d5787c
feat: add `from_service_account_info` (#67)
yoshi-automation Mar 30, 2021
63519f5
chore(deps): update dependency google-cloud-scheduler to v2.2.0 (#72)
renovate-bot Apr 1, 2021
a53f45b
chore: migrate to owl bot (#82)
parthea May 12, 2021
1aeabac
chore(deps): update dependency flask to v1.1.3 (#87)
renovate-bot May 14, 2021
b70b6a8
chore(deps): update dependency pytest to v6.2.4 (#85)
renovate-bot May 14, 2021
c10480f
chore(deps): update dependency flask to v2 (#83)
renovate-bot May 14, 2021
ec1dfc4
chore(deps): update dependency flask to v2.0.1 (#92)
renovate-bot May 21, 2021
cb7e224
chore: new owl bot post processor docker image (#94)
gcf-owl-bot[bot] May 22, 2021
55f24a1
chore(deps): update dependency google-cloud-scheduler to v2.3.0 (#107)
renovate-bot Jul 3, 2021
3b4dd7d
feat: add Samples section to CONTRIBUTING.rst (#111)
gcf-owl-bot[bot] Jul 22, 2021
fbaf3f4
chore(deps): update dependency google-cloud-scheduler to v2.3.1 (#113)
renovate-bot Jul 22, 2021
c8b896f
chore(deps): update dependency google-cloud-scheduler to v2.3.2 (#119)
renovate-bot Jul 29, 2021
6781a8e
chore: fix INSTALL_LIBRARY_FROM_SOURCE in noxfile.py (#121)
gcf-owl-bot[bot] Aug 11, 2021
e293c92
chore: drop mention of Python 2.7 from templates (#123)
gcf-owl-bot[bot] Aug 13, 2021
5ea3801
chore(deps): update dependency pytest to v6.2.5 (#128)
renovate-bot Aug 31, 2021
27a3549
chore: blacken samples noxfile template (#132)
gcf-owl-bot[bot] Sep 17, 2021
0ff898d
chore(deps): update dependency google-cloud-scheduler to v2.3.3 (#137)
renovate-bot Sep 27, 2021
c126e4f
chore: fail samples nox session if python version is missing (#140)
gcf-owl-bot[bot] Sep 30, 2021
a91d748
chore(deps): update dependency google-cloud-scheduler to v2.3.4 (#141)
renovate-bot Sep 30, 2021
5c935a8
chore(python): Add kokoro configs for python 3.10 samples testing (#147)
gcf-owl-bot[bot] Oct 8, 2021
da79254
chore(deps): update dependency flask to v2.0.2 (#142)
renovate-bot Oct 8, 2021
b1c3617
chore(deps): update dependency google-cloud-scheduler to v2.4.0 (#148)
renovate-bot Oct 12, 2021
bed5ebc
chore(deps): update dependency google-cloud-scheduler to v2.5.0 (#154)
renovate-bot Oct 25, 2021
6b4d434
chore(python): run blacken session for all directories with a noxfile…
gcf-owl-bot[bot] Nov 11, 2021
f13312b
chore(samples): Add check for tests in directory (#172)
gcf-owl-bot[bot] Jan 11, 2022
73fee33
chore(python): Noxfile recognizes that tests can live in a folder (#176)
gcf-owl-bot[bot] Jan 19, 2022
a670145
chore(deps): update dependency google-cloud-scheduler to v2.6.0 (#182)
renovate-bot Feb 7, 2022
16675ec
chore(deps): update dependency pytest to v7 (#188)
renovate-bot Feb 8, 2022
8cb0024
chore(deps): update dependency pytest to v7.0.1 (#190)
renovate-bot Feb 14, 2022
2ec7d60
chore(deps): update dependency flask to v2.0.3 (#191)
renovate-bot Feb 23, 2022
6c5028d
chore(deps): update all dependencies (#196)
renovate-bot Feb 28, 2022
89f34e7
chore: Adding support for pytest-xdist and pytest-parallel (#204)
gcf-owl-bot[bot] Mar 4, 2022
0be5f30
chore(deps): update dependency google-cloud-scheduler to v2.6.2 (#207)
renovate-bot Mar 7, 2022
0dc68ec
chore(deps): update dependency pytest to v7.1.0 (#209)
renovate-bot Mar 13, 2022
474f483
chore(deps): update dependency pytest to v7.1.1 (#210)
renovate-bot Mar 19, 2022
846f3eb
chore(python): use black==22.3.0 (#215)
gcf-owl-bot[bot] Mar 28, 2022
07798d7
chore(deps): update dependency flask to v2.1.0 (#214)
renovate-bot Mar 30, 2022
bced293
chore(deps): update dependency flask to v2.1.1 (#217)
renovate-bot Mar 30, 2022
90d1dfb
chore(deps): update dependency google-cloud-scheduler to v2.6.3 (#228)
renovate-bot Apr 14, 2022
b34c0f5
chore(python): add nox session to sort python imports (#229)
gcf-owl-bot[bot] Apr 21, 2022
70a1393
chore(deps): update dependency pytest to v7.1.2 (#232)
renovate-bot Apr 25, 2022
b16e42f
chore(deps): update dependency flask to v2.1.2 (#234)
renovate-bot Apr 28, 2022
658b898
fix: require python 3.7+ (#256)
gcf-owl-bot[bot] Jul 10, 2022
8033d12
chore(deps): update all dependencies (#248)
renovate-bot Jul 16, 2022
fd7bcc8
chore(deps): update all dependencies (#262)
renovate-bot Aug 2, 2022
95134d1
chore(deps): update all dependencies (#263)
renovate-bot Aug 2, 2022
87edcb8
chore(deps): update all dependencies (#265)
renovate-bot Aug 5, 2022
52af804
chore(deps): update all dependencies (#266)
renovate-bot Aug 9, 2022
178a74e
chore(deps): update dependency google-cloud-scheduler to v2.7.1 (#271)
renovate-bot Aug 16, 2022
d3fa282
chore(deps): update dependency pytest to v7.1.3 (#281)
renovate-bot Sep 6, 2022
9f76a9e
chore: detect samples tests in nested directories (#286)
gcf-owl-bot[bot] Sep 13, 2022
d0233de
chore(deps): update dependency google-cloud-scheduler to v2.7.2 (#290)
renovate-bot Oct 4, 2022
75c9e22
chore(deps): update dependency google-cloud-scheduler to v2.7.3 (#293)
renovate-bot Oct 10, 2022
824d0a7
chore(deps): update dependency pytest to v7.2.0 (#294)
renovate-bot Oct 26, 2022
938c067
chore(python): drop flake8-import-order in samples noxfile (#299)
gcf-owl-bot[bot] Nov 26, 2022
8e89227
chore(deps): update dependency google-cloud-scheduler to v2.8.0 (#305)
renovate-bot Dec 15, 2022
8efe9e5
chore(python): add support for python 3.11 (#306)
gcf-owl-bot[bot] Jan 6, 2023
9b4d5c1
chore(deps): update dependency google-cloud-scheduler to v2.9.0 (#309)
renovate-bot Jan 10, 2023
c781e8f
chore(deps): update dependency pytest to v7.2.1 (#310)
renovate-bot Jan 14, 2023
9cfbd69
chore(deps): update dependency google-cloud-scheduler to v2.9.1 (#314)
renovate-bot Jan 24, 2023
1934ff5
chore(deps): update all dependencies (#321)
renovate-bot Mar 1, 2023
794e2de
chore(deps): update dependency pytest to v7.2.2 (#326)
renovate-bot Mar 4, 2023
89a650b
chore(deps): update dependency google-cloud-scheduler to v2.11.0 (#329)
renovate-bot Apr 6, 2023
cd8dab9
Merge remote-tracking branch 'migration/main' into python-scheduler-m…
Apr 11, 2023
dddd0e2
Update license header
MiaCY Apr 11, 2023
af35759
Update license header
MiaCY Apr 11, 2023
d8cedb4
add noxfile_config and remove README
Apr 11, 2023
f0644eb
Merge branch 'main' into python-scheduler-migration
nicain Apr 11, 2023
beb77fa
address linter
Apr 11, 2023
781680f
Merge branch 'main' into python-scheduler-migration
MiaCY Apr 12, 2023
0209cf7
add codeowner of scheduler samples
Apr 12, 2023
40f3f99
Merge branch 'main' into python-scheduler-migration
parthea Apr 18, 2023
56fdd58
Merge branch 'main' into python-scheduler-migration
cojenco Apr 20, 2023
2b67631
Merge branch 'main' into python-scheduler-migration
cojenco Apr 20, 2023
53babdc
fix region tags
cojenco Apr 21, 2023
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
/recaptcha_enterprise/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers
/recaptcha_enterprise/demosite/* @Sita04 @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/recaptcha-customer-obsession-reviewers @GoogleCloudPlatform/python-samples-reviewers
/run/**/* @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/python-samples-reviewers
/scheduler/**/* @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/python-samples-reviewers
/secretmanager/**/* @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/python-samples-reviewers
/securitycenter/**/* @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/python-samples-reviewers
/speech/**/* @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/python-samples-reviewers
Expand Down
3 changes: 0 additions & 3 deletions scheduler/README.md

This file was deleted.

18 changes: 18 additions & 0 deletions scheduler/snippets/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.

# [START cloudscheduler_python_yaml]
runtime: python37
service: my-service
# [END cloudscheduler_python_yaml]
75 changes: 75 additions & 0 deletions scheduler/snippets/create_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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.


def create_scheduler_job(project_id, location_id, service_id):
"""Create a job with an App Engine target via the Cloud Scheduler API"""
# [START cloudscheduler_create_job]
from google.cloud import scheduler

# Create a client.
client = scheduler.CloudSchedulerClient()

# TODO(developer): Uncomment and set the following variables
# project_id = 'PROJECT_ID'
# location_id = 'LOCATION_ID'
# service_id = 'my-service'

# Construct the fully qualified location path.
parent = f"projects/{project_id}/locations/{location_id}"

# Construct the request body.
job = {
"app_engine_http_target": {
"app_engine_routing": {"service": service_id},
"relative_uri": "/log_payload",
"http_method": 1,
"body": "Hello World".encode(),
},
"schedule": "* * * * *",
"time_zone": "America/Los_Angeles",
}

# Use the client to send the job creation request.
response = client.create_job(request={"parent": parent, "job": job})

print("Created job: {}".format(response.name))
# [END cloudscheduler_create_job]
return response


def delete_scheduler_job(project_id, location_id, job_id):
"""Delete a job via the Cloud Scheduler API"""
# [START cloudscheduler_delete_job]
from google.api_core.exceptions import GoogleAPICallError
from google.cloud import scheduler

# Create a client.
client = scheduler.CloudSchedulerClient()

# TODO(developer): Uncomment and set the following variables
# project_id = 'PROJECT_ID'
# location_id = 'LOCATION_ID'
# job_id = 'JOB_ID'

# Construct the fully qualified job path.
job = f"projects/{project_id}/locations/{location_id}/jobs/{job_id}"

# Use the client to send the job deletion request.
try:
client.delete_job(name=job)
print("Job deleted.")
except GoogleAPICallError as e:
print("Error: %s" % e)
# [END cloudscheduler_delete_job]
34 changes: 34 additions & 0 deletions scheduler/snippets/create_job_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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_job

TEST_PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
TEST_LOCATION = os.getenv("LOCATION_ID", "us-central1")


def test_create_job(capsys):
create_result = create_job.create_scheduler_job(
TEST_PROJECT_ID, TEST_LOCATION, "my-service"
)
out, _ = capsys.readouterr()
assert "Created job:" in out

job_name = create_result.name.split("/")[-1]
create_job.delete_scheduler_job(TEST_PROJECT_ID, TEST_LOCATION, job_name)

out, _ = capsys.readouterr()
assert "Job deleted." in out
44 changes: 44 additions & 0 deletions scheduler/snippets/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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 Cloud Scheduler samples."""

# [START cloudscheduler_app]
from flask import Flask, request

app = Flask(__name__)


# Define relative URI for job endpoint
@app.route("/log_payload", methods=["POST"])
def example_task_handler():
"""Log the job payload."""
payload = request.get_data(as_text=True) or "(empty payload)"
print("Received job with payload: {}".format(payload))
return "Printed job payload: {}".format(payload)


# [END cloudscheduler_app]


@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)
46 changes: 46 additions & 0 deletions scheduler/snippets/main_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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("/log_payload", data=payload)
assert r.status_code == 200

out, _ = capsys.readouterr()
assert payload in out


def test_empty_payload(capsys, app):
r = app.post("/log_payload")
assert r.status_code == 200

out, _ = capsys.readouterr()
assert "empty payload" in out
42 changes: 42 additions & 0 deletions scheduler/snippets/noxfile_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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.

# 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.
"ignored_versions": ["2.7", "3.6"],
# 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',
# If you need to use a specific version of pip,
# change pip_version_override to the string representation
# of the version number, for example, "20.2.4"
"pip_version_override": None,
# A dictionary you want to inject into your test. Don't put any
# secrets here. These values will override predefined values.
"envs": {},
}
1 change: 1 addition & 0 deletions scheduler/snippets/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest==7.2.2
3 changes: 3 additions & 0 deletions scheduler/snippets/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Flask==2.2.3
gunicorn==20.1.0
google-cloud-scheduler==2.11.0