Merge branch 'main' into avm99963-monorail
Merged commit 34d8229ae2b51fb1a15bd208e6fe6185c94f6266
GitOrigin-RevId: 7ee0917f93a577e475f8e09526dd144d245593f4
diff --git a/framework/cloud_tasks_helpers.py b/framework/cloud_tasks_helpers.py
index bd9b7f9..89954e3 100644
--- a/framework/cloud_tasks_helpers.py
+++ b/framework/cloud_tasks_helpers.py
@@ -1,4 +1,4 @@
-# Copyright 2020 The Chromium Authors. All rights reserved.
+# Copyright 2020 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""A helper module for interfacing with google cloud tasks.
@@ -12,6 +12,7 @@
from __future__ import print_function
import logging
+import six
from six.moves import urllib
from google.api_core import exceptions
@@ -21,7 +22,8 @@
if not settings.unit_test_mode:
import grpc
- from google.cloud import tasks
+ from google.cloud import tasks_v2
+ from google.cloud.tasks_v2.services import cloud_tasks
_client = None
# Default exponential backoff retry config for enqueueing, not to be confused
@@ -35,10 +37,11 @@
global _client
if not _client:
if settings.local_mode:
- _client = tasks.CloudTasksClient(
+ transport = cloud_tasks.transports.CloudTasksGrpcTransport(
channel=grpc.insecure_channel(settings.CLOUD_TASKS_EMULATOR_ADDRESS))
+ _client = tasks_v2.CloudTasksClient(transport=transport)
else:
- _client = tasks.CloudTasksClient()
+ _client = tasks_v2.CloudTasksClient()
return _client
@@ -74,7 +77,7 @@
target = task.get('app_engine_http_request').get('relative_uri')
kwargs.setdefault('retry', _DEFAULT_RETRY)
logging.info('Enqueueing %s task to %s', target, parent)
- return client.create_task(parent, task, **kwargs)
+ return client.create_task(parent=parent, task=task, **kwargs)
def generate_simple_task(url, params):
@@ -91,7 +94,7 @@
'app_engine_http_request':
{
'relative_uri': url,
- 'body': urllib.parse.urlencode(params),
+ 'body': six.ensure_binary(urllib.parse.urlencode(params)),
'headers': {
'Content-type': 'application/x-www-form-urlencoded'
}