Compatibility with `google.appengine.api.taskqueue`? - `create_queue` needs `/` in your lib but can't have it here
Opened this issue · 0 comments
SamuelMarks commented
from os import environ
import grpc
from google.cloud.tasks_v2 import CloudTasksClient
from google.cloud.tasks_v2.services.cloud_tasks.transports import CloudTasksGrpcTransport
def setup_taskqueue(queue_id):
task_emulator_host = 'localhost:8000'
channel = grpc.insecure_channel(task_emulator_host)
# Before v2.0.0 of the client
# client = CloudTasksClient(channel=channel)
transport = CloudTasksGrpcTransport(channel=channel)
client = CloudTasksClient(transport=transport)
parent = 'projects/{project_id}/locations/us-central1'.format(project_id=environ["DATASTORE_PROJECT_ID"])
# queue_name = '{}/queues/test'.format(parent)
queue_name = "projects/{project_id}/locations/{location_id}/queues/{queue_id}".format(
project_id=environ["DATASTORE_PROJECT_ID"],
location_id='us-central1',
queue_id=queue_id
)
client.create_queue(queue={'name': queue_name}, parent=parent)
client.create_task(task={'http_request': {'http_method': 'GET', 'url': 'https://www.google.com'}},
parent=queue_name) # 200
environ["DEFAULT_VERSION_HOSTNAME"] = task_emulator_host
Some relevant dependencies:
https://cloud.google.com/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/taskqueue/taskqueue
https://pypi.org/project/gcloud-tasks-emulator/
https://pypi.org/project/appengine-python-standard/
So if I make queue_name
equal to queue_id
I get:
Traceback (most recent call last):
[…]
client.create_queue(queue={'name': queue_id}, parent=parent)
File "env/lib/python3.10/site-packages/google/cloud/tasks_v2/services/cloud_tasks/client.py", line 825, in create_queue
response = rpc(
File "env/lib/python3.10/site-packages/google/api_core/gapic_v1/method.py", line 113, in __call__
return wrapped_func(*args, **kwargs)
File "env/playable-3-10/lib/python3.10/site-packages/google/api_core/timeout.py", line 120, in func_with_timeout
return func(*args, **kwargs)
File "env/lib/python3.10/site-packages/google/api_core/grpc_helpers.py", line 74, in error_remapped_callable
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InvalidArgument: 400 Queue name must be formatted: "projects/<PROJECT_ID>/locations/<LOCATION_ID>/queues/<QUEUE_ID>"
Whereas if I keep queue_name
with its fully-qualified path, later from:
queue_id='foo'
taskqueue \
.Task(url="/_{}".format(queue_id), payload=payload, target=queue_id) \
.add(queue_name=queue_id)
Then I get:
google.appengine.api.taskqueue.taskqueue.UnknownQueueError
Whereas if I use the queue_name
from the aformentioned setup_taskqueue
function; the error ensues:
Traceback (most recent call last):
[…]
taskqueue.Task(url="/_foo", payload=payload, target="foo").add(
File "env/lib/python3.10/site-packages/google/appengine/api/taskqueue/taskqueue.py", line 1294, in add
return self.add_async(queue_name, transactional).get_result()
File "env/lib/python3.10/site-packages/google/appengine/api/taskqueue/taskqueue.py", line 1289, in add_async
return Queue(queue_name).add_async(self, transactional, rpc)
File "env/lib/python3.10/site-packages/google/appengine/api/taskqueue/taskqueue.py", line 1636, in __init__
raise InvalidQueueNameError(
google.appengine.api.taskqueue.taskqueue.InvalidQueueNameError: Queue name does not match pattern "^[a-zA-Z0-9-]{1,100}$"; found projects/PROJECT_NAME/locations/us-central1/queues/foo
How do a jerryrig your emulator into my project so I can run tests offline?
Thanks