【问题标题】:Google Cloud Scheduler calling Google Cloud Function when Function has succeeded (returned 200 status) still gets 500 statusGoogle Cloud Scheduler 在 Function 成功时调用 Google Cloud Function(返回 200 状态)仍然获得 500 状态
【发布时间】:2020-05-19 17:41:35
【问题描述】:

我有一个调度程序作业每小时调用一次我的函数。该功能正常工作,并且每次都返回 HTTP 200 状态。但是,每 3-5 次调用,调度程序作业就会返回 HTTP 500 状态。此问题的原因/解决方法是什么?

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

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 

这些是调度程序日志中的示例

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"  
}

【问题讨论】:

  • 您的函数调用似乎平均需要几分钟才能完成,有没有超过 10 分钟?您可能会达到调度程序等待响应时间的上限。
  • 您是否为函数和/或 Cloud Scheduler 设置了特殊的超时/参数?
  • @guillaume blaquiere - 是的,在 gso_gabriel 的回答下查看我的 cmets

标签: google-cloud-platform google-cloud-functions google-cloud-scheduler


【解决方案1】:

我遇到了完全相同的问题。虽然您还不能在控制台中看到它,但 Google Cloud Scheduler 有一些标志,您可以通过 gcloud scheduler jobs create http 命令设置。这是我正在使用的示例:

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

尤其是在运行持续几分钟而不是几秒钟的函数时,尝试截止日期似乎很重要。设置这些标志减轻了我的一些问题,但不是全部。有关更多标志,请参阅documentation。

此外,如果这没有帮助,则可能是 Google 内部某处的服务器端错误。这是由于 UNKNOWN 错误状态,您可以在此 table 中查找。我自己,我得到了一个内部错误状态,也称为服务器端错误。对谷歌不是特别有帮助..

【讨论】:

  • 谢谢你,你也可以像这样编辑截止日期gcloud scheduler jobs update http JOBNAME --attempt-deadline 30M
  • 真的!但是,云函数的最大超时时间为 9 分钟,这就是我在示例中将调度程序尝试截止时间设置为 10m 的原因。
  • 当然,但您的示例通常不是首选,因为您必须先删除您遇到问题的作业,我说“就像这样”,而不是“完全像这样,超时 Nebulastic想要”
【解决方案2】:

考虑到这些请求所花费的时间,这似乎导致 Google 调度程序超时,最终导致某些调用失败。

根据文档cron.yaml Reference,您可以在那里配置调度程序在超时之前将花费的最长时间。我建议您查看它并确认您的配置方式,并尝试将您的调用保持在您的 cron.yaml 文件中设置的时间内。

如果信息澄清并帮助您,请告诉我!

【讨论】:

  • 嗨@gso_gabriel。感谢您的答复。我不认为我理解你的回答。我从控制台创建了调度程序作业。没有 cron.yaml 文件。我也没有在控制台中看到任何标识我可以配置的超时的内容。 “cron.yaml 参考”是 App Engine 参考,我没有为此使用 App Engine。 My Cloud Function 配置了 540 秒的超时,当它到达该截止日期的 30 秒时,它有意退出。显示的持续时间最长为 380,000 毫秒,即 380 秒,因此少于 540。
  • 如果您引用的页面适用于调度程序,则默认超时应为 10 分钟或 600 秒。所以,我所有的调用都比这短。
  • 嗨@KevinBuchs 感谢您的澄清!我已经检查并进一步搜索。这似乎与谷歌面临的一个错误有关。我建议您通过 1:1 支持与他们联系,以便他们更好地为您提供帮助。您可以通过他们的GCP Support 与他们联系。
  • 我们为 Production 基于角色的支持计划支付了一个多月的费用。我发现质量很差,实际上我不得不投入更多时间来跟上支持人员的误解和缺乏知识。我决定,如果我自己只是四处寻找解决方案,我会走在前面。如果你有时间分享你是如何检查和搜索的,我一个人可能会更强大。
猜你喜欢
  • 2022-01-22
  • 2019-01-18
  • 1970-01-01
  • 2017-12-17
  • 1970-01-01
  • 1970-01-01
  • 2021-04-17
  • 1970-01-01
  • 2021-06-14
相关资源
最近更新 更多