Not able to call cloud firestore and cloud task api from app engine flexible environment

56 views
Skip to first unread message

ASHIK RANJAN

unread,
Mar 17, 2021, 9:42:51 AM3/17/21
to Google App Engine
When calling the cloud task and cloud firestore API from app engine flexible environment running flask application, I am getting no error/response for a long time and it gets timed out.

But same API call is working fine from another server outside of google cloud using the same service account.

Can you please help me if the above two API can be called from the app engine flexible environment or if some settings need to be changed?

jlibera

unread,
Mar 17, 2021, 4:15:36 PM3/17/21
to Google App Engine
Hi,

Would you be able to please provide a screenshot or full log the error message/response you are seeing? This will help to better visualize and diagnose as to why these are occurring in the first place. Better yet, I would suggest to open an public issue tracker ticket [1] to look into your inquiry further.

Would you be able to provide a little more details regarding your implementation as well as application architecture? This will help to better visualize how these components are integrated, as well as provide possible alternatives for the bottlenecks that your app is experiencing.

ASHIK RANJAN

unread,
Mar 18, 2021, 9:47:01 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/0657990c-5d35-4d59-9fdc-ebfa09c5863bn%40googlegroups.com.

jlibera

unread,
Mar 22, 2021, 5:16:12 PM3/22/21
to Google App Engine
Hi, 

Thanks for providing this information about your app.

Regarding your error, are the timeouts still reoccurring? How often do these timeouts occur (daily, intermittently, etc.)? It would also be helpful to have a screenshot of the error message; this will provide us details of the necessary steps for mitigating this issue for your application.

For readability and troubleshooting purposes, it would be beneficial to bring this issue to the App Engine team via Issue tracker as provided from the previous message. Have you managed to open up a public issue tracker ticket already for your issue?

ASHIK RANJAN

unread,
Mar 23, 2021, 1:07:45 AM3/23/21
to google-a...@googlegroups.com
Basically I not getting any error when calling the required function to create a task or the function for crud on firestore.
After a certain time, periods request is killed by the server(app engine).

No, I have not created public issues for the same.

David (Cloud Platform Support)

unread,
Mar 23, 2021, 4:21:30 PM3/23/21
to Google App Engine

Hello,

I would recommend you to follow the snippet provided in here. Also, please take a look at this Issue Tracker which may provide with some help regarding firewall rules. Now, I’m providing you this information as Google Groups is reserved for conceptual discussions only and not meant to be a place to troubleshoot issues. If none of these links provide you with information to get it working, I would recommend you to directly contact Google Cloud Platform Support since they would be able to inspect your project and troubleshoot the issue with you. Please note that unless you are in a free trial, you will require to purchase a support package. If you are on a free trial, you may be able to receive free trial support.

Reply all
Reply to author
Forward
0 new messages