Skip to content

Instantly share code, notes, and snippets.

@iseebi
Last active January 7, 2021 10:50
Show Gist options
  • Save iseebi/782a0b3e6c84e79507e8a18bec39e829 to your computer and use it in GitHub Desktop.
Save iseebi/782a0b3e6c84e79507e8a18bec39e829 to your computer and use it in GitHub Desktop.
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore
# Python pycache:
__pycache__/
# Ignored by the build system
/setup.cfg
Pipfile
Pipfile.lock
runtime: python37
entrypoint: gunicorn -b :$PORT main:app
import flask
import os
from google.cloud import tasks_v2 as tasks
app = flask.Flask(__name__)
project = os.environ['GOOGLE_CLOUD_PROJECT']
service = os.environ['GAE_SERVICE']
version = os.environ['GAE_VERSION']
queue_region = "us-central1"
queue_name = 'test-dispatch'
@app.route('/enqueue1', methods=['POST'])
def enqueue1():
print("Enqueue1 in PROJECT: {}, SERVICE: {}, VERSION: {}".format(project, service, version))
request_task = {
'app_engine_http_request': {
'http_method': 'POST',
'relative_uri': '/task'
}
}
tasks_client = tasks.CloudTasksClient()
tasks_queue = tasks_client.queue_path(project, queue_region, queue_name)
tasks_client.create_task(tasks_queue, request_task)
return 'ok'
@app.route('/enqueue2', methods=['POST'])
def enqueue2():
print("Enqueue2 in PROJECT: {}, SERVICE: {}, VERSION: {}".format(project, service, version))
request_task = {
'app_engine_http_request': {
'http_method': 'POST',
'relative_uri': '/task',
'app_engine_routing': {
'service': service,
'version': version,
'instance': ''
}
}
}
tasks_client = tasks.CloudTasksClient()
tasks_queue = tasks_client.queue_path(project, queue_region, queue_name)
tasks_client.create_task(tasks_queue, request_task)
return 'ok'
@app.route('/task', methods=['POST'])
def task():
print("Tasks Running in PROJECT: {}, SERVICE: {}, VERSION: {}".format(project, service, version))
return 'ok'
if __name__ == '__main__':
app.run()
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
flask = "*"
google = "*"
google-cloud-tasks = "==1.5.0" # gloud-tasks-emulator not supports 2.0.0
gunicorn = "*"
[dev-packages]
[requires]
python_version = "3.7"
[scripts]
start = "flask run --debugger --reload"
deploy = "gcloud app deploy --project iseteki-test-ct-queue"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment