Local development with Cloud Tasks & Cloud Datastore with GAE with Python3

Viewed 1626

Context:- We are using GAE with Python3 and so GAE APIs package isn't available so we are using google-cloud-* packages for interacting with GAE services

i.e. google-cloud-tasks for push queues, google-cloud-datastore for datastore.

Problem:- There is no way to test things in development environment as google-cloud-* packages directly act on production services.
i.e. if I push a task using google-cloud-tasks it would push in production queue, similarly if I create or update an entity from development environment it would be updating entity in production datastore.

Earlier with GAE APIs packages in local system it used to have local cloud tasks and datastore for development purpose.

I see it as a big and very common issue, I wonder if someone else as well faced such issue and found any solution to this.

3 Answers

This Local Emulator for Google Cloud Tasks worked for me.

pip install gcloud-tasks-emulator
gcloud-tasks-emulator start --port=9090

// Note -: by default the gcloud-tasks-emulator command does not available globally switch installation directory.

/Users/{userName}/Library/Python/3.7/bin
./gcloud-tasks-emulator start --port=9090

Now we can add code changes to support cloud task in local env.

import grpc
from google.cloud.tasks_v2 import CloudTasksClient
from google.cloud.tasks_v2.gapic.transports.cloud_tasks_grpc_transport import C 
loudTasksGrpcTransport

client = CloudTasksClient(
 transport=CloudTasksGrpcTransport
 (channel=grpc.insecure_channel("127.0.0.1:9090"))
)

visit this link for complete instruction https://pypi.org/project/gcloud-tasks-emulator/

Related