0

Is there a possible way to run the admin api method "Patch" through "Cloud Scheduler"?

My functionality works perfectly when run through the API Explorer.

w/ servingStatus as the updateMask and this as the request body

{
  "servingStatus": "USER_DISABLED"
}

But if I run a request through the cloud scheduler, at the time I want it to run, I get a 404 error.

Target : HTTP

URL : https://appengine.googleapis.com/v1/apps/[APP-ID]/services/default/?updateMask=servingStatus

POST BODY : 
{
  "servingStatus": "USER_DISABLED"
}

It's possible I have the url syntax wrong but I couldn't find anything that differs than the one I got.

Note: My goal is to shutdown the server at the specific time.

3 Answers3

0

From the current documentation of creating a scheduler job found here, if we look at the --http-method flag we find that is is documented as restricted to be one of:

  • delete
  • get
  • head
  • post
  • put

Explicitly, we do not see patch. Confirming that patch is the correct HTTP command we look here and do indeed see that to be correct.

The next thought that might be of value to us is to realize that Cloud Scheduler can fire either an HTTP or a PubSub event and doesn't actually care where that event is targeted. What this means is that we could create a Cloud Function which encapsulates the idea that when the Cloud Function is called it encapsulates your desired server shutdown. If the Cloud Function owns the shutdown then the puzzle changes from how do we drive Cloud Scheduler to call AppEngine Admin Api to how do we call the Cloud Function which owns shutting down the server? This is much easier and likely more robust. You can configured your Cloud Function to respond to a REST request via GET or POST and have Cloud Scheduler submit that request.

Kolban
  • 13,794
  • 3
  • 38
  • 60
  • https://cloud.google.com/nodejs/docs/reference/libraries If we scroll down to App engine admin api we can see we get a 404. GREAT! – Tom Welling Apr 01 '19 at 04:11
  • I think the link on the page may be old / broken. I think this is the new link we want. https://github.com/googleapis/google-api-nodejs-client/tree/master/src/apis/appengine – Kolban Apr 01 '19 at 14:05
0

Before using Appengine API it is necessary to complete preliminary steps, described in the documentation:

  1. Initialize gcloud.
  2. Enable the Google App Engine Admin API, and any other API needed.
  3. Authorize HTTPs request.

Please check quick start how to use Cloud Scheduler. There is also information what API you need to enable.

Correct scope for Cloud Scheuler API is https://cloudscheduler.googleapis.com

And also information how to use PATCH request, that should look like that:

PATCH https://cloudscheduler.googleapis.com/v1/{job.name=projects/*/locations/*/jobs/*}

Pawel Czuczwara
  • 1,442
  • 9
  • 20
-1

First, create service acc. and then paste service acc. name in cloud invoker. your problem will solve. otherwise, check this video("https://www.youtube.com/watch?v=t7e0dNSCmzI").