首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调用Google函数当函数成功时(返回200状态)仍然获得500状态

调用Google函数当函数成功时(返回200状态)仍然获得500状态
EN

Stack Overflow用户
提问于 2020-02-03 22:42:39
回答 2查看 2.3K关注 0票数 1

我有一个调度器工作,每小时打一次电话给我的函数。该函数工作正常,每次都返回HTTP 200状态。然而,每3到5个调用,Scheduler作业返回一个HTTP 500状态。造成这个问题的原因/解决方法是什么?

示例:下面是函数日志显示的内容:

代码语言:javascript
复制
D 2020-02-03T10:02:10.958520185Z Function execution took 130785 ms, finished with status code: 200 
D 2020-02-03T11:01:40.819608573Z Function execution took 99762 ms, finished with status code: 200 
D 2020-02-03T12:01:41.049430737Z Function execution took 100126 ms, finished with status code: 200 
D 2020-02-03T13:02:07.369401657Z Function execution took 127213 ms, finished with status code: 200 
D 2020-02-03T14:04:24.352839424Z Function execution took 263896 ms, finished with status code: 200 
D 2020-02-03T15:03:14.664760657Z Function execution took 194125 ms, finished with status code: 200 
D 2020-02-03T16:06:23.162542969Z Function execution took 382609 ms, finished with status code: 200 
D 2020-02-03T17:03:17.458640891Z Function execution took 196799 ms, finished with status code: 200 
D 2020-02-03T18:02:54.614556691Z Function execution took 170119 ms, finished with status code: 200 
D 2020-02-03T19:04:43.064083790Z Function execution took 277775 ms, finished with status code: 200 
D 2020-02-03T20:02:59.315497864Z Function execution took 178499 ms, finished with status code: 200 

以下是Scheduler日志中的示例

代码语言:javascript
复制
2020-02-03 11:03:00.567 CST
{"jobName":"projects/my-project/locations/us-west2/jobs/my-function-trigger","targetType":"HTTP","url":"https://us-central1-my-function.cloudfunctions.net/analytics-archiver","status":"UNKNOWN","@type":"type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished"}
{
 httpRequest: {
 }
 insertId: "redacted"  
 jsonPayload: {
  @type: "type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished"   
  jobName: "projects/my-project/locations/us-west2/jobs/my-function-trigger"   
  status: "UNKNOWN"   
  targetType: "HTTP"   
  url: "https://us-central1-my-project.cloudfunctions.net/my-function"   
 }
 logName: "projects/my-project/logs/cloudscheduler.googleapis.com%2Fexecutions"  
 receiveTimestamp: "2020-02-03T17:03:00.567786781Z"  
 resource: {
  labels: {
   job_id: "my-function-trigger"    
   location: "us-west2"    
   project_id: "my-function"    
  }
  type: "cloud_scheduler_job"   
 }
 severity: "ERROR"  
 timestamp: "2020-02-03T17:03:00.567786781Z"  
}


2020-02-03 13:03:00.765 CST
{"jobName":"projects/my-project/locations/us-west2/jobs/my-function-trigger","targetType":"HTTP","url":"https://us-central1-my-project.cloudfunctions.net/my-function","status":"UNKNOWN","@type":"type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished"}
Expand all | Collapse all{
 httpRequest: {
 }
 insertId: "redacted"  
 jsonPayload: {
  @type: "type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished"   
  jobName: "projects/my-project/locations/us-west2/jobs/my-function-trigger"   
  status: "UNKNOWN"   
  targetType: "HTTP"   
  url: "https://us-central1-my-project.cloudfunctions.net/my-function"   
 }
 logName: "projects/my-project/logs/cloudscheduler.googleapis.com%2Fexecutions"  
 receiveTimestamp: "2020-02-03T19:03:00.765993324Z"  
 resource: {
  labels: {
   job_id: "my-function-trigger"    
   location: "us-west2"    
   project_id: "my-project"    
  }
  type: "cloud_scheduler_job"   
 }
 severity: "ERROR"  
 timestamp: "2020-02-03T19:03:00.765993324Z"  
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-02-04 14:50:56

考虑到这些请求所花费的时间,这似乎导致了Google上的超时,最终导致一些调用失败。

根据文档cron.yaml参考,您可以在计划程序超时之前配置最大时间。我建议您查看它并确认您的调用是如何配置的,并尝试在cron.yaml文件上设置的时间内保持调用。

让我知道,如果信息澄清和帮助你!

票数 1
EN

Stack Overflow用户

发布于 2020-03-05 19:33:13

我也有同样的问题。虽然您还不能在控制台中看到它,但是Google有一些可以通过gcloud scheduler jobs create http命令设置的标志。这是我使用的一个例子:

代码语言:javascript
复制
gcloud scheduler jobs create http my-job \
  --schedule="0 * * * *" \
  --uri=https://europe-west1-${PROJECT_ID}.cloudfunctions.net/my-func/ \
  --http-method=POST \
  --message-body="my-body" \
  --max-retry-attempts 3 \
  --max-backoff 10s \
  --attempt-deadline 10m

特别是在运行持续几分钟而不是几秒钟的函数时,尝试-最后期限似乎是很重要的。设置这些旗子可以减轻我的一些问题,但不是所有的问题。有关更多标志,请参阅文档

此外,如果这没有帮助,它可能是一个服务器端的错误,在某个地方的幕后谷歌。这是由于未知的错误状态,您可以在这个表格中查找它。我自己得到了一个内部错误状态,这也被称为服务器端错误。对谷歌没有多大帮助..。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60048174

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档