Firestore and Cloud task api not callable from app engine flexible

52 views
Skip to first unread message

ASHIK RANJAN

unread,
Mar 17, 2021, 9:43:01 AM3/17/21
to Google App Engine
I want to use cloud task api to create task and push in the queue from the app engine flexible environment but it doesn't work and also not able to use firestore api in native mode.

Same API is working fine from the server outside of google cloud using the same service account credentials.

Can you please help if we can use both the api from the app engine or I need to make some changes in the settings.

Elliott (Cloud Platform Support)

unread,
Mar 17, 2021, 11:04:43 AM3/17/21
to Google App Engine

Hello,


I understand that you want to use the Cloud Tasks API to create a task and push in a queue from the app engine flexible environment but it doesn't work. Also you are not able to use the Firestore API in native mode.

You’ve also mentioned that an API is working fine from outside of google cloud using the same service account credentials.

In addition, you asked for some help with settings.

To determine a common issue, can you please tell me more about your code and where you get stuck? Are there error messages? Google Groups is meant for general discussions about Google products and if a scenario is determined to be a common issue, an Issue Tracker may be created. Right now, I do not have enough information to decide the next steps.

Would you provide this information for the benefit of the community and if it is common, others the groups may be able to recognize it.

I hope that after getting your details, some advice will be offered.

I will wait for your response.

ASHIK RANJAN

unread,
Mar 18, 2021, 9:47:18 AM3/18/21
to google-a...@googlegroups.com
I am using the flask application on the google app engine flexible environment.

1. I want to create a task whenever some URL has been hit by a user and queues should hit the google app engine endpoint for executing the task. For example, I am appending the code here
The same code is working fine and creating a task if executed from another server

import json
import datetime
from google.cloud import tasks_v2beta3
from google.protobuf import timestamp_pb2

import json
import datetime
from google.cloud import tasks_v2beta3
from google.protobuf import timestamp_pb2


class CloudTaskManager:
    def __init__(self):
        self.client = tasks_v2beta3.CloudTasksClient()

    def create_task(self, project, queue, location, payload=None, in_seconds=5):
        parent = self.client.queue_path(project, location, queue)

        task = {
            'app_engine_http_request': {
                'http_method': tasks_v2beta3.HttpMethod.POST,
                'relative_uri': '/api/v1/rating/cloud_task_handler',
                'headers': {
                    'Content-Type': 'application/json',
                    'Org_Name': 'organization1'
                },
                'body': json.dumps(payload).encode()
            }
        }

        if in_seconds is not None:
            d = datetime.datetime.utcnow() + datetime.timedelta(seconds=in_seconds)
            timestamp = timestamp_pb2.Timestamp()
            timestamp.FromDatetime(d)
            task['schedule_time'] = timestamp

        response = self.client.create_task(parent=parent, task=task)
        return response

2. Another case is that I want to use cloud firestore API that is in native mode and the code snippet are as below.
   cred = credentials.Certificate('name.json')  
    # cred = credentials.ApplicationDefault()
    if not firebase_admin._apps:
        firebase_admin.initialize_app(cred, {
          'projectId': 'project-id',
        })
    db = firestore.client()
    collection_refs = db.collection('collection-name')
    documents = collection_refs.stream()
    for doc in documents:
        return doc.to_dict()

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-appengi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/73e344f4-862e-465d-a1e6-857219e4fd28n%40googlegroups.com.

ASHIK RANJAN

unread,
Mar 22, 2021, 1:13:53 AM3/22/21
to Google App Engine
Can anyone help me with how to resolve the above issues?

wokmou

unread,
Mar 22, 2021, 9:24:16 AM3/22/21
to Google App Engine

From the description above you are facing issues using Cloud Tasks API with app engine as well as using Firestore API.

This page [1] provides you with a tutorial on how to Create tasks from App Engine app Using Cloud Tasks to trigger Cloud Functions.

Also, this Cloud Firestore Android Codelab [2] allows you to emulate and experiment with Firestore APIs and sample code.

If the issue you are experiencing is related to a malfunction of one of the Google platform services please refer to this page[3] so that a support agent can have a look at your project.

[1]https://cloud.google.com/tasks/docs/samples/cloud-tasks-app

[2]https://firebase.google.com/codelabs/firestore-android#0

[3]https://cloud.google.com/support/docs/issue-trackers

Reply all
Reply to author
Forward
0 new messages