使用Google Cloud Scheduler调度作业。

huangapple go评论63阅读模式
英文:

Scheduling a job with google cloud scheduler

问题

I have a cloud function that works perfectly with this code and me testing it in google cloud.

import requests

url = 'https://europe-central2-spiritual-grin-390008.cloudfunctions.net/function-4'
headers = {'Content-Type': 'application/json'}

response = requests.post(url, headers=headers, json={})

if response.status_code == 200:
    print('Function executed successfully.')
    print('Response:', response.text)
else:
    print('Function execution failed. Status code:', response.status_code, response.text)

On cloud, I have created a service account that has editor, cloud function invoker, and cloud scheduler runner permissions. While creating a scheduler, I have the same region, putting that service account. On the cloud function, too, I'm using the same service account. In the headers of cloud scheduler, I'm giving the same headers that I have in my code, and then the cloud adds a second header of User-Agent: Google-Cloud-Scheduler.

But when I run the scheduler, it gives me an error of INVALID ARGUMENT. Can you tell me what might be wrong and what can I do to fix it?

I tested that same service account with a basic cloud function and scheduler, and it worked. So I'm assuming it's not a service account's problem.

This is the full error from the cloud:

{"@type":"type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished", "jobName":"projects/spiritual-grin-390008/locations/europe-central2/jobs/near_earth_asteroid_data", "status":"INVALID_ARGUMENT", "targetType":"HTTP", "url":"https://europe-central2-spiritual-grin-390008.cloudfunctions.net/function-4"}
英文:

i have a cloud function that works perfectly with this code and me testing it in google cloud.

code to run cloud function

import requests

url = 'https://europe-central2-spiritual-grin-390008.cloudfunctions.net/function-4'
headers = {'Content-Type': 'application/json'}  


response = requests.post(url, headers=headers, json={})

if response.status_code == 200:
    print('Function executed successfully.')
    print('Response:', response.text)
else:
    print('Function execution failed. Status code:', response.status_code, response.text)

on cloud i have created a service account that has editor, cloud function invoker, and cloud scheduler runner permissions.
while creating a scheduler i have the same region, putting that servoce account, on cloud function too im using same service account. in headers of cloud scheduler im giving same headers that i have in my code and then cloud adds second header of User-Agent: Google-Cloud-Scheduler

but when i run the scheduler it gives me an error of INVALID ARGUMENT, can you tell me what might be wrong and what can i do to fix it.

i tested that same service account with basic cloud function and scheduler and it worked so im assuming its not a service accounts problem

this is the full error from cloud

{"@type":"type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished", "jobName":"projects/spiritual-grin-390008/locations/europe-central2/jobs/near_earth_asteroid_data", "status":"INVALID_ARGUMENT", "targetType":"HTTP", "url":"https://europe-central2-spiritual-grin-390008.cloudfunctions.net/function-4"}

答案1

得分: 1

以下是翻译好的部分:

有几个因素可能会导致“INVALID_ARGUMENT”错误:

  1. 您的客户端可能配置错误,发送错误的日志名称或其他参数。您可以检查您的URL配置:

    https://europe-central2-spiritual-grin-390008.cloudfunctions.net/function-4
    

    而不是:

    https://www.europe-central2-spiritual-grin-390008.cloudfunctions.net/function-4
    
  2. 检查您的服务帐号是否具有正确的权限。您可以按照此链接上的说明进行操作:使用HTTP目标进行身份验证

如果上述步骤仍然不起作用,您可以联系Google Cloud支持,或者您可以将此问题报告为错误

希望这能帮助您。

英文:

There are several factors that may cause INVALID_ARGUMENT error:

  1. Your client might be misconfigured, sending out a wrong log name or other arguments. You may check your URL config:

    https://europe-central2-spiritual-grin-390008.cloudfunctions.net/function-4
    

    as opposed to:

    https://www.europe-central2-spiritual-grin-390008.cloudfunctions.net/function-4
    
  2. Check your service account if it has the correct permissions. You may follow the instructions through this link on using authentication with HTTP targets.

If the aforementioned steps still didn't work, you may reach out to Google Cloud Support or you could file this as a bug.

Hope this helps.

huangapple
  • 本文由 发表于 2023年6月26日 19:18:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76556179.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定