How to prevent Google Cloud Engine to run multiple concurrent instances? - google-app-engine

Hi I'm deploying a very simple python code to Google App Engine just to test how Google App Engine works, that I'll later use for my real more complex code that I have tested locally. The problem is that Google App Engine logs is showing that I'm running multiple services / threads / instances / modules or whatever that name is... CONCURRENTLY
This is my code: main.py
import time
def executeSomething():
#code here
print("Hello world!")
time.sleep(5)
while True:
executeSomething()
and app.yaml
runtime: python38
service: default
handlers:
- url: /
script: auto
manual_scaling:
instances: 1
I deploy using gcloud app deploy --stop-previous-version --version test-0-0-3
Then I tail the logs using gcloud app logs tail -s default
2022-08-09 15:59:18 default[test-0-0-3] Hello world!
2022-08-09 15:59:18 default[test-0-0-3] Hello world!
2022-08-09 15:59:18 default[test-0-0-3] Hello world!
2022-08-09 15:59:18 default[test-0-0-3] Hello world!
2022-08-09 15:59:23 default[test-0-0-3] Hello world!
2022-08-09 15:59:23 default[test-0-0-3] Hello world!
2022-08-09 15:59:23 default[test-0-0-3] Hello world!
2022-08-09 15:59:23 default[test-0-0-3] Hello world!
2022-08-09 15:59:28 default[test-0-0-3] Hello world!
2022-08-09 15:59:28 default[test-0-0-3] Hello world!
2022-08-09 15:59:28 default[test-0-0-3] Hello world!
2022-08-09 15:59:28 default[test-0-0-3] Hello world!
2022-08-09 15:59:33 default[test-0-0-3] Hello world!
2022-08-09 15:59:33 default[test-0-0-3] Hello world!
2022-08-09 15:59:33 default[test-0-0-3] Hello world!
2022-08-09 15:59:33 default[test-0-0-3] Hello world!
As you can see, there are 4 concurrent services running. Idk what is it called: services / threads / instances, but the problem is it's running several codes concurrently.
In my real code, I only want to run 1 service because I am afraid if I run multiple concurrently, it will create duplicates in the data I'm inserting to DB.

From the comments, the OP wants to run a daily task with CRON jobs. In this case, the number of instances doesn't matter and the CRON job will run only once.
You will see multiple instances at deployment, but with Google App Engine standard, you should have 0 or 1 paid instance running at all times and you should be easily able to say within the free quota.
GAE is a good solution for this task.

Related

"gcloud app deploy" hangs on "Building and pushing image for service"

I suddenly can't deploy using gcloud app deploy.
It hangs on "Building and pushing image for service [default]". At that time, the Python process takes 99% CPU, and continues until the deploy times out. I've tried upgrading Python to no avail.
It occurs regardless of Google Appengine Project. Have tried installing different versions of gcloud CLI to no avail.
My teammates can deploy successfully using the same commands. Any ideas?
EDIT:
The app.yaml file:
runtime: nodejs
env: flex
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 6
disk_size_gb: 10
env_variables:
...
Output of my gcloud app deploy verbosity=debug: https://gist.github.com/bbarton/05b8ae514849a5731101afb5ae639357

systemV to systemd executing a simple c program as a services but cannot find printf debugs on console

Hi I am trying to write a systemd service to launch a simple hello world program at bootup. I am unable to see the simple printf statements on the /dev/ttymcx0 which is my terminal. Is there a way where i could let the systemd service to print to the terminal. when i run the status i can see that the service is running.
[Unit]
Description=Hello world service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
StandardOutput=journal+console
Restart=always
RestartSec=1
ExecStart=/bin/sh /usr/bin/helloworld.sh
[Install]
WantedBy=multi-user.target
This is my sample c application
#include <stdio.h>
int main(void){
while(1){
printf("test print \n");
usleep(3000);
}
return 0;
}
this is my shell script calling the c application
#!/bin/bash
cd /usr/bin
helloworld
When i see the systemctl status helloworld I can the the service as running but it does not seem to print any debug messages to the terminal.
I can see the service running but do not see the printf printing messages to the console.

heroku - could not find a javascript runtime

I am getting the following error message in the heroku logs when trying to access the application from the browser:
Gem Load Error is: Could not find a
JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.
This is being triggered by a couple of gems - ngannotate-rails and coffee-rails.
This is a rails 4.2 application with a angular.js frontend, being deployed to heroku for the first time.
Heroku stack:
$ heroku stack
=== my_app Available Stacks
heroku-16
* cedar-14
Buildpacks:
$ heroku buildpacks
=== my_app Buildpack URLs
1. https://github.com/prakashmurthy/heroku-buildpack-nodejs
2. heroku/ruby
Both the node.js build and ruby build complete successfully.
PATH seems to be set correctly:
$ heroku run bash
Running bash on ⬢ my_app... up, run.1502 (Free)
~ $ echo $PATH
/app/bin:/app/vendor/bundle/bin:/app/vendor/bundle/ruby/2.3.0/bin:/usr/local/bin:/usr/bin:/bin
Appreciate any help in figuring out this issue.

Pydev + Google App Engine + Eclipse = dev_appserver terminates right on

i've been a happy user for pydev, eclipse and gae.
Now i've changed my computer and reinstalled the latest jee eclipse, pydev and gae. As usual, I configure my pydev gae project (I use App Engine Modules), have it launched by the eclipse debugger.
The issue is that as soon as I launch a cron task through the admin interface (localhost:8000/cron), every thread terminates and the dev_appserver ends (exit value : 137)
Everything run smooth when launching dev_appserver.py by hand and with pycharm (i'd like to keep using pydev!)
versions
Google Cloud SDK 0.9.33
app-engine-python 1.9.12
eclipse 4.4.1
pydev 3.8.0.201425
Debug windows content
<terminated>xxxx xxxx (1) [PyDev Google App Run]
<terminated>dev_appserver.py
dev_appserver.py
dev_appserver.py
dev_appserver.py
<terminated, exit value: 137>dev_appserver.py
console ouput
pydev debugger: starting (pid: 20240)
INFO 2014-10-15 10:27:19,522 api_server.py:171] Starting API server at: http://localhost:34966
INFO 2014-10-15 10:27:19,523 dispatcher.py:174] Starting dispatcher running at: http://localhost:8080
INFO 2014-10-15 10:27:19,553 dispatcher.py:186] Starting module "default" running at: http://localhost:8081
INFO 2014-10-15 10:27:19,586 dispatcher.py:186] Starting module "static-backend" running at: http://localhost:8082
INFO 2014-10-15 10:27:19,589 admin_server.py:117] Starting admin server at: http://localhost:8000
pydev debugger: starting (pid: 20264)

Glide/Gaelyk/Groovy: Error deploying to Google App Engine: Can’t enter oauth2 token

As part of the deployment process of a Glide project (http://glide-gae.appspot.com/docs/intro step 3 of 2nd section) you need to authenticate using oauth2. My browser popped up with the token as expected but the process didn’t wait for me to copy the code in, it just carried on with the following error...
22:30:12.713 [DEBUG] [org.gradle.launcher.daemon.server.DaemonStateCoordinator] Daemon is busy, sleeping until state changes.
22:30:12.733 [INFO] [org.gradle.launcher.daemon.server.exec.LogToClient] About to start relaying all logs to the client via the connection.
22:30:12.734 [INFO] [org.gradle.launcher.daemon.server.exec.LogToClient] The client will now receive all logging from the daemon (pid: 12557). The daemon log file: /.gradle/daemon/1.8/daemon-12557.out.log
22:30:12.739 [DEBUG] [org.gradle.launcher.daemon.server.SynchronizedDispatchConnection] thread 14: received class org.gradle.launcher.daemon.protocol.CloseInput
22:30:12.740 [DEBUG] [org.gradle.launcher.daemon.server.DefaultDaemonConnection] Received IO message from client: CloseInput[id=069864b2-2948-4a9d-abea-0705274136a1.2]
22:30:12.741 [INFO] [org.gradle.launcher.daemon.server.exec.ForwardClientInput] Closing daemon's stdin at end of input.
22:30:12.742 [INFO] [org.gradle.launcher.daemon.server.exec.ForwardClientInput] The daemon will no longer process any standard input.
22:30:12.747 [INFO] [org.gradle.launcher.daemon.server.exec.ExecuteBuild] Executing build with daemon context: DefaultDaemonContext[uid=3901cff0-8d50-41b6-9459-e31f7b78f1e3,javaHome=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home,daemonRegistryDir=.gradle/daemon,pid=12557,idleTimeout=10800000,daemonOpts=-XX:MaxPermSize=256m,-Xmx512m,-Dfile.encoding=UTF-8]
Please enter code: Encountered a problem: No line found
Please see the logs [/var/folders/c8/vx2jf50j68x1z3_pysy6kxjm0000gp/T/appcfg2389447403250678065.log] for further information.
Daemon vm is shutting down... The daemon has exited normally or was terminated in response to a user interrupt.
----- End of the daemon log -----
org.gradle.tooling.GradleConnectionException: Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.8-bin.zip'.
What can I do to be able to deploy my application? How can I force the process to wait for me to enter the code?
If that's (glide deploy) not working for you, the easiest option is to export the app as a standard gradle project and then execute the gaeUpdate task.
glide -a somedir/yourapp -o where/you/want/to/export/app export
Note that the export is command at the end, -o tell the location where it should be exported.
Then from the exported project run: gradle gaeUpdate
A work around is to manually set your credentials in the GAE build.gradle file.
Update the following file:
/glide/install/generated/app-name/build.gradle
appcfg {
email = ‘email-address'
password = ‘password'
app {
id = ‘app-id'
}
}
This means that the values from the __glide.groovy file are ignored, but at least you can get the application deployed

Resources