I have an Google App Engine instance that is started every 15 minutes using a Cron job: it simply gets a https request every 15 minutes. The server then runs a number of cron jobs and needs to terminate. I have setup the server with a yaml file that starts with:
runtime: php81
service: crontask
instance_class: B4
basic_scaling:
max_instances: 1
idle_timeout: 2m
This works most of the time: the instance starts, the jobs run and then the instance terminates 2 minutes after completing the job. But sometimes (once every few weeks) the instance keeps on running for 24 hours (the maximum timeout from GAE), which breaks the cron job running at that moment.
Question: I want to programmatically terminate the server at the end if the job. So the server needs to send a termination signal to itself. Is this possible?
The CLI program gcloud allows you to shutdown an instance as documented in https://cloud.google.com/sdk/gcloud/reference/app/instances/delete and the parameters are all available as environment variables:
GAE_INSTANCE - instance id
GAE_VERSION - version
GAE_SERVICE - service name
So I am thinking it should be possible to call the same url called by gcloud to delete/shutdown the instance, but I haven't found the docs how to do this.