Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Standardize on CamelCase, reword confusing endpoint name [(#1288)](Go…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsg authored Dec 19, 2017
1 parent e07a260 commit a6fa0fd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions samples/appengine/flexible/tasks/create_app_engine_queue_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ def create_task(project, queue, location, payload=None, in_seconds=None):
client = googleapiclient.discovery.build('cloudtasks', 'v2beta2')

# Construct the request body.
url = '/log_payload'
url = '/example_task_handler'
body = {
'task': {
'app_engine_http_request': { # Specify the type of request.
'http_method': 'POST',
'relative_url': url
'appEngineHttpRequest': { # Specify the type of request.
'httpMethod': 'POST',
'relativeUrl': url
}
}
}
Expand All @@ -50,15 +50,15 @@ def create_task(project, queue, location, payload=None, in_seconds=None):
converted_payload = base64_encoded_payload.decode()

# Add the payload to the request.
body['task']['app_engine_http_request']['payload'] = converted_payload
body['task']['appEngineHttpRequest']['payload'] = converted_payload

if in_seconds is not None:
# Convert "seconds from now" into an rfc3339 datetime string.
d = datetime.datetime.utcnow() + datetime.timedelta(seconds=in_seconds)
scheduled_time = d.isoformat('T') + 'Z'

# Add the rfc3339 datetime string to the request.
body['task']['schedule_time'] = scheduled_time
body['task']['scheduleTime'] = scheduled_time

# Construct the fully qualified queue name.
queue_name = 'projects/{}/locations/{}/queues/{}'.format(
Expand Down Expand Up @@ -104,7 +104,7 @@ def create_task(project, queue, location, payload=None, in_seconds=None):
)

parser.add_argument(
'--in_seconds',
'--in_seconds', type=int,
help='The number of seconds from now to schedule task attempt.'
)

Expand Down
4 changes: 2 additions & 2 deletions samples/appengine/flexible/tasks/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
app = Flask(__name__)


@app.route('/log_payload', methods=['POST'])
def log_payload():
@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('Received task with payload: {}'.format(payload))
Expand Down
4 changes: 2 additions & 2 deletions samples/appengine/flexible/tasks/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def test_index(app):
def test_log_payload(capsys, app):
payload = 'test_payload'

r = app.post('/log_payload', data=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('/log_payload')
r = app.post('/example_task_handler')
assert r.status_code == 200

out, _ = capsys.readouterr()
Expand Down

0 comments on commit a6fa0fd

Please sign in to comment.