Skip to content

Commit

Permalink
Standardize on CamelCase, reword confusing endpoint name (#1288)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsg committed Dec 19, 2017
1 parent 4f0ebc5 commit cd4d473
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions appengine/flexible/tasks/create_app_engine_queue_task.py
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 appengine/flexible/tasks/main.py
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 appengine/flexible/tasks/main_test.py
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
4 changes: 2 additions & 2 deletions tasks/pull_queue_snippets.py
Expand Up @@ -47,7 +47,7 @@ def create_task(project, queue, location):
# Construct the request body.
task = {
'task': {
'pull_message': {
'pullMessage': {
'payload': converted_payload
}
}
Expand Down Expand Up @@ -77,7 +77,7 @@ def pull_task(project, queue, location):

duration_seconds = '600s'
pull_options = {
'max_tasks': 1,
'maxTasks': 1,
'leaseDuration': duration_seconds,
'responseView': 'FULL'
}
Expand Down

0 comments on commit cd4d473

Please sign in to comment.