Local development with Cloud Tasks & Cloud Datastore with GAE with Python3
Asked Answered
R

3

7

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.

Rutaceous answered 18/12, 2018 at 3:57 Comment(2)
As someone who've been using python2.7 App Engine for ~10+ years, I'm perplexed by this approach too - no more local development it seems ...Gastrolith
Yeah, checked with google cloud support guys about it and last time I checked this wasn't in their scope of things.Rutaceous
C
6

For Cloud Datastore you can follow the instructions at https://cloud.google.com/datastore/docs/tools/datastore-emulator to use the local emulator instead of your production Datastore database.

As noted in https://cloud.google.com/tasks/docs/migrating, Cloud Tasks is not currently supported in an emulator.

Casey answered 18/12, 2018 at 16:40 Comment(1)
Are you aware of any updated to this? Is it still impossible to run some copy of cloud tasks locally for unit-testing/local-development purposes?Interact
E
1

I built an in-process emulator for Python development.

See also some emulators that run in a separate process in localhost: Potato London’s gcloud-tasks-emulator, mentioned in the answer above, and Aert van de Hulsbeek’s cloud-tasks-emulator.

Elliellicott answered 9/8, 2020 at 12:12 Comment(0)
C
0

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/

Cheeks answered 16/7, 2020 at 4:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.