How can I tell an Google App Engine app to stop itself? - google-app-engine

At a high level: When deployed, I want my Google App Engine app to run through some code and then stop the program automatically once it's finished, so that I don't have to manually stop the versions or instances using the UI.
I tried using the both the stop and delete instances in the Google Compute Engine API here: https://cloud.google.com/compute/docs/reference/latest/instances/delete
When I do that it gives me a successful response with a status equal to 'PENDING.' But when I look at the logs for the app, rather than stopping it looks like it's just repeating the code that I deployed over and over again, which I interpret as, "Oh it must not be stopping the app/instances then."
Am I doing something wrong? Is there another way to tell a Google App Engine app to stop itself?

I'm not sure exactly what you're trying to do, but it seems like you want the App Engine Admin API, rather than the Compute Engine API. I think setting servingStatus via app.services.versions.patch is probably what you want, but I'm not sure.

Related

Google Cloud: misterious constant 0.033/s compute request APIs

I open a new project on Google Cloud, and I start a default Standard Env App Engine. I don't do anything else, and I start to get mysterious non-zero traffic to my project.
I specifically keep getting a alternating 0.033/s and 0.017/s request per seconds on the project. This is not specific to this project but to ALL my google cloud projects. Also I get 100% errors rate. I trying to investigate but I didn't even know where to start.
Where can I get more information on what this APIs requests are specifically? And why this happens?

Switching from App Engine Flex to Standard

I created an App Engine Flex NodeJS app, not realizing that there is no free tier. So I decided to switch to App Engine standard. I updated my app.yaml, deployed, and everything seems to be working. However, I deployed this a couple hours ago, and I still have 2 compute engine instances running. Is there something I need to do to shut those down, or did I just not wait long enough? I don't want them running at all because I don't want to pay for them, especially since the standard app doesn't use compute engine at all.
I tried going to the Compute Engine tab in GCP to see if I could do anything there, but all I get is a "Create instance" button.
Check the Versions page on the Google Cloud Console and make sure that the old version is deleted and that traffic is going to the new version. It may be a good idea to use a new version for the standard env.
Then on the Instances page check if the respective instances are running and shut them down if so.

LiteIDE for Go in Google App Engine

It seems to me that LiteIDE is a good environment to get started with Go...
But in order to debug, it's asking me for the following:
What should I set these to if I'm developing a Google App Engine app?
I need the ability to detect and give hints to compile-time errors in the IDE. That should also be the case when using GAE-specific APIs (Channel API, etc.)
Though for runtime errors, I would assume that those are better left to visiting the dev site.
In other words- the way Google App Engine does things if I understand correctly, is you launch dev_appserver.py and then you don't actually recompile/relaunch again, the dev server does all of that and you simply visit http://localhost:8080 to test it, and it will give runtime errors descriptively in the browser.

Where are the GAE Backends logs?

As soon as I figured out how to invoke my app as a Backends app, my log messages stopped appearing.
I found this helpful post which says the Backends logs are kept separately and that I need to switch to Backends view by selecting the named backend from the dropdown at the top of the admin console, but I don't see anything Backends specific in that list to select.
Perhaps this is a clue... when I invoke my app via myapp.appspot.com/dostuff, in the log I see I'm getting the DeadlineExceededError after 60 secs, indicating it's not running as a Backends app. But when I invoke it via mybackend.myapp.appspot.com/dostuff, it continues running as needed, but no log entries!
Seems like I'm missing something. Thanks.
Somehow my app wasn't fully recognized by GAE as a Backend app. And therefore my backend instances weren't available in the drop-list. Seeing that others had similar trouble with a Python 2.7 app (ex.) that had been initially uploaded as a 2.5 app, I created a new app in GAE and uploaded to there and it worked. Sorry I don't have a more definitive answer.
Before all was working well, I also ended up creating an empty /_ah/start handler as suggested by someone in this thread. Also if you're deploying a multi-threaded backend, make sure to check this post out -- there's some important stuff I didn't run across in the docs.

Google app engine - initialize object at start up

I am developing a GWT application on google app engine and I am looking for the best approach to initialize objects (like singleton, list, shared resources etc).
I guess I am looking for something like "Spring application context file"
any ideas?
What you're looking for is here:
http://code.google.com/appengine/docs/java/config/appconfig.html#Using_a_ServletContextListener
Basically, you're going to make a Servlet Context Listener, which is a part of the servlet API designed for exactly what you're referring to. If you're running this locally, it will run when you start your server. In the app engine environment it should run for every warm up request (to avoid, this, you can use "Always ON", which will be set here: http://code.google.com/appengine/docs/adminconsole/instances.html#Always_On)
Besides ServletContextListener you can also use <load-on-startup> to mark your normal servlet to be invoked during a warmup request.

Resources