Google Cloud Scheduler:为什么cloud function运行成功但logger仍然报错?
Google Cloud Scheduler: Why cloud function runs successfully but logger still shows error?
我设置了一个 google 云调度程序作业,它通过 HTTP 触发云功能。我可以确定云函数已被触发并成功运行——它产生了预期的结果。
但是,调度程序作业仍然显示“失败”并且记录器如下:
{
"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"
}
我已经粘贴了下面的云功能代码,并进行了必要的编辑以删除敏感信息:
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'
我可以确定的是,函数结束前的那一行,DING_BOT.send_text(msg)
执行成功。我收到了短信。
这里有什么云不对?
这是一个常见问题,因为 UI 部分 Google 云控制台。因此,我假设您仅使用控制台设置调度程序。
因此,您需要创建或使用 command line (GCLOUD) or API (but GCLOUD is easier), to add the "attempt-deadline" parameter.
更新它
事实上 Cloud Scheduler 也有一个超时时间(默认为 60 秒),如果 URL 没有在这个时间范围内应答,调用将被视为失败
把这个参数增加到250s,应该就可以了。
注意:您还可以使用 CLI 设置重试策略,如果您需要它可能会很有趣!
我设置了一个 google 云调度程序作业,它通过 HTTP 触发云功能。我可以确定云函数已被触发并成功运行——它产生了预期的结果。 但是,调度程序作业仍然显示“失败”并且记录器如下:
{
"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"
}
我已经粘贴了下面的云功能代码,并进行了必要的编辑以删除敏感信息:
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'
我可以确定的是,函数结束前的那一行,DING_BOT.send_text(msg)
执行成功。我收到了短信。
这里有什么云不对?
这是一个常见问题,因为 UI 部分 Google 云控制台。因此,我假设您仅使用控制台设置调度程序。
因此,您需要创建或使用 command line (GCLOUD) or API (but GCLOUD is easier), to add the "attempt-deadline" parameter.
更新它事实上 Cloud Scheduler 也有一个超时时间(默认为 60 秒),如果 URL 没有在这个时间范围内应答,调用将被视为失败
把这个参数增加到250s,应该就可以了。
注意:您还可以使用 CLI 设置重试策略,如果您需要它可能会很有趣!