-1

I set up a google cloud scheduler job that triggers a cloud function through HTTP. I can be sure that the cloud function is triggered and runs successfully - it has produced the expected outcome. However, the scheduler job still shows "failed" and the logger is like:

{
  "insertId": "8ca551232347v49",
  "jsonPayload": {
    "jobName": "projects/john/locations/asia-southeast2/jobs/Get_food",
    "status": "UNKNOWN",
    "url": "https://asia-southeast2-john.cloudfunctions.net/Get_food",
    "@type": "type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished",
    "targetType": "HTTP"
  },
  "httpRequest": {},
  "resource": {
    "type": "cloud_scheduler_job",
    "labels": {
      "job_id": "Get_food",
      "location": "asia-southeast2",
      "project_id": "john"
    }
  },
  "timestamp": "2020-10-22T04:08:24.521610728Z",
  "severity": "ERROR",
  "logName": "projects/john/logs/cloudscheduler.googleapis.com%2Fexecutions",
  "receiveTimestamp": "2020-10-22T04:08:24.521610728Z"
}

I have pasted the cloud function code below with edits necessary to remove sensitive information:

import requests
import pymysql 
from pymysql.constants import CLIENT
from google.cloud import storage
import os
import time 
from DingBot import DING_BOT 
from decouple import config
import datetime 

BUCKET_NAME = 'john-test-dataset'
FOLDER_IN_BUCKET = 'compressed_data'
LOCAL_PATH = '/tmp/'



TIMEOUT_TIME = 500


def run(request):
    """Responds to any HTTP request.
    Args:
        request (flask.Request): HTTP request object.
    Returns:
        The response text or any set of values that can be turned into a
        Response object using
        `make_response <http://flask.pocoo.org/docs/1.0/api/#flask.Flask.make_response>`.
    """
        
    while True:
        # some code that will be break the loop in about 200 seconds

    DING_BOT.send_text(msg)
    return 'ok'

what I can be sure of is that the line right before the end of the fucntion, DING_BOT.send_text(msg) executed successfully. I have received the text message.

What cloud be wrong here?

Kid_Learning_C
  • 2,605
  • 4
  • 39
  • 71
  • Would you like to edit the question to share the code of the [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) that anyone can copy and use to reproduce this behavior? – Doug Stevenson Oct 22 '20 at 05:10
  • How long take your fonction to be executed? Did you try to set the return code at the end of your function `return 'OK', 200`? – guillaume blaquiere Oct 22 '20 at 07:45
  • Could you please take a look at your [Stackdriver](https://cloud.google.com/products/operations) and get further logs? It's needed for information to better understand your case, as without using Cloud Scheduler, your Cloud Function is working per your say. – gso_gabriel Oct 22 '20 at 13:14
  • @guillaumeblaquiere I tried it but it did not have any effect. The cloud function runs successfully, but the cloud scheduler shows "failed" nonetheless. – Kid_Learning_C Oct 28 '20 at 10:02
  • @gso_gabriel I have looked into stackdriver... the above pasted error message is the only thing I could get. The logs for cloud function shows that all has run successfully. The cloud scheduler shows "failed" nonetheless, and when I dig into its detailed logs in stackdriver, the error message is the only thing I could get. – Kid_Learning_C Oct 28 '20 at 10:05
  • @Kid_Learning_C, you didn't answer the first part of my question: How many seconds take your function? – guillaume blaquiere Oct 28 '20 at 12:39
  • @guillaumeblaquiere There is a while loop in the code which does some query search on DB and It takes about 200 seconds to finish; I have already set the function timeout to the max (540 sec) and I still got the issue described as above. – Kid_Learning_C Oct 31 '20 at 11:08

1 Answers1

2

It's a common problem because of partial UI of Google Cloud Console. So, I took the hypothesis that you set up your scheduler only with the console.

So, you need to create, or to update it with command line (GCLOUD) or API (but GCLOUD is easier), to add the "attempt-deadline" parameter.

In fact Cloud Scheduler also have a timeout (60s by default)and if the URL don't answer in this timeframe, the call is considered as fail

Increase this param to 250s, and it should be OK.

Note: you can also set retry policies with the CLI, it could be interesting if you need it!

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76