Search code examples
graphqlgoogle-cloud-rungoogle-cloud-scheduler

How to schedule a call to a GraphQL endpoint using Google Cloud Scheduler


I have an GraphQL application running in a instance of Google Cloud Run.

I would like to keep the run instance warm. So, I'm trying to configure Google Cloud Scheduler call a ping endpoint.

Below the curl command that calls the endpoint:

curl 'https://myapi-xxxxxx-xx.x.run.app/' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Connection: keep-alive' -H 'Authorization: bearer 123456' --data-binary '{"query":"\n{\n  ping\n}\n\n  ","variables":{}}' --compressed

How can I create a new schedule to do a similar call to the endpoint ?


Solution

  • You may be interesting in Cloud Scheduler having HTTP as a target. The documentation shows all the needed steps to create a cron job:

    • Specify the fully qualified URL of the endpoint the job will contact.

    • Specify the HTTP method. The default is POST.

    • Optionally, specify the data to be sent to the target. This data is sent in the body of the request as bytes when either the POST or PUT HTTP method is selected.

    • To create an HTTP target job that requires authentication, see Using Authentication with HTTP Targets

    The last point is only needed if you need to authenticate the requests to your Cloud Run service.