I have a cloud function calling another cloud function in python. My issue is that when I call the next function, the first one waits for its execution or times out.
The key is that this is about Google Cloud Functions. Particularly as mismatch between function timeout and maximum API call rate. My issue is that the function's maximum timeout (540 seconds) is shorter than the time I need to make the required API calls and that I don't want to create more triggers.
How can I make the first (the "caller") finish, after calling the second function, that does its work? Some sample code:
# main.py
# url: this-particular-cloud-function
# function initiated with a post request containing {"previous_tin_index": 0}
import requests
import time
import logging
final_tin_index = 100
def eat_spam(request):
started_eating_spam = time.time()
spam_json = request.get_json()
spam_to_eat = spam_json["previous_tin_index"]
for spam in range(spam_to_eat):
time.sleep(5)
previous_tin_index += 1
logging.info("I hate spam....")
finished_previous_spam_time = time.time() - started_eating_spam
if finished_previous_spam_time >= 10:
logging.info("Make it stop!")
requests.post("this-particular-cloud-function", json={"previous_tin_index": previous_tin_index})
return "200"
EDIT: I know that the inherent problem is that the function never reaches the return value. I am wondering if this can be fixed, other than, for example, rewriting the code into a Javascript promise.
P.S. I looked at the Cloud Documentation, but python seems to be lacking in the particular example.