Google Cloud CronJob NodeJs fails and no logs - node.js

I have created a google cloud app ( with nodeJS ) . That have 1 endpoing with the app.yaml
runtime: nodejs
env: flex
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 1
disk_size_gb: 10
And a cronJob with a cron.yaml that calls to this endpoint like this :
cron:
- description: "Lead Data Update"
url: /cronjobPrivate/processLeads
schedule: every 1 minutes
I'm gettin crazy because if i try to access from the url of my cloud app like
https://[my-project].appspot.com/cronjobPrivate/processLeads The response is correct and the app is working.
But the cronjob always says "fails" and does not create any record on the logs.
I have read the documentation of google but i didn't find nothing. Maybe i'm missing something between the cronjobs <-> app service ...but i don't know what...

Related

How can I specify scaling settings in app.yaml correctly?

I'm deploying a node.js backend app on App Engine standard environment
the app.yaml file looks like this:
runtime: nodejs12
env_variables:
NODE_ENV: 'production'
automatic_scaling:
min_num_instances: 1
max_num_instances: 100
cpu_utilization:
target_utilization: 0.9
but on deploy it says
RROR: (gcloud.app.deploy) INVALID_ARGUMENT: Frontend automatic scaling should NOT have the following parameter(s): [max_total_instances, min_total_instances, cpu_utilization.target_utilization] (or "version.env" should be set to "flex"
- '#type': type.googleapis.com/google.rpc.BadRequest
fieldViolations:
- description: 'Frontend automatic scaling should NOT have the following parameter(s):
[max_total_instances, min_total_instances, cpu_utilization.target_utilization]
(or "version.env" should be set to "flex"'
field: version.automatic_scaling
as far as the official docs are concerned, the automatic scaling part should work on standard if the instance is at least F1(which it is) so I don't get why it tells me that i should set the environment to flex and I cannot find anything about this issue on the webs
Checking the official documentation on the scaling options for the standard environment on App Engine, it seems like you need to correct the parameters' naming.
In your particular case, you can make it work using the following:
runtime: nodejs12
env_variables:
NODE_ENV: 'production'
automatic_scaling:
min_instances: 1
max_instances: 100
target_cpu_utilization: 0.9
I could reproduce this in the Cloud Shell and worked without issues.

Google App Engine Cron Job target does not use correct url

I have a problem getting a cron job to correctly target a specific service on the Google App Engine Standard for a python app.
I can successfully create a cron job for a python app on Google App Engine (Standard) with the app.yaml file and a cron.yaml file. The service is not defined and is the default service. the cron.yaml does not specify a target.
If I set the service name in the app.yaml file to service1,
the URL for the app changes from projectID.ew.r.appspot.com to service1-dot-projectID.ew.r.appspot.com.
Next, I specify the target in the cron job to service1 and redeploy the app.yaml and cron.yaml.
The cron job now fails with status 400 every time it runs.
From what I can see in the ProtoPayLoad logs, the host is not using the correct URL.
The cron job uses the URL service1.projectID.ew.r.appspot.com, according the protoPayLoad "host" value in the log. The cron job returns a Status 400.
Why does the cron job not use the service1-dot-projectID.ew.r.appspot.com URL?
What can I do to get the cron job to correctly target a specific service?
#app.yaml with working cron job
#project URL: projectID.ew.r.appspot.com
runtime: python38
handlers:
- url: /static
static_dir: static/
- url: /.*
script: auto
#cron.yaml with working cron job
cron:
- description: "working cron job"
url: /myjob/
schedule: every 2 minutes
Here are the versions of files for the broken cron job
#app.yaml with broken cron job
#project URL: service1-dot-projectID.ew.r.appspot.com
service: service1
runtime: python38
handlers:
- url: /static
static_dir: static/
- url: /.*
script: auto
#cron.yaml with working cron job
cron:
- description: "working cron job"
url: /myjob/
schedule: every 2 minutes
target: service1
The error in the app engine log file has the protoPayLoad details.
host:"service1.projectID.ew.r.appspot.com"
I think it should be the following
host:"service1-dot-projectID.ew.r.appspot.com"
My project has multiple services deployed that will use cron jobs specific to each service.
I cannot just use the default service name.
I appreciate all the help.
It is only after posting a question do you find the answer.
This project is a Django project.
The django Settings file has a list of URLs defined in the ALLOWED_HOSTS variable.
service1-dot-projectID.ew.r.appspot.com was defined but
service1.projectID.ew.r.appspot.com was not defined.
Once this was added, the cron job worked perfectly, targeting a service as normal.

500 HTTP Error When Deploying to DigitalOcean App Platform via Doctl

I've created a YAML spec for my DO App Platform based on the sample on this repository.
The reason I couldn't simply use the UI on the DigitalOcean website is that my project is a monorepo.
Which looks like this:
name: unique-expressions
services:
- name: api
environment_slug: node-js
github:
repo: Valencian-Digital/unique-expressions
branch: main
deploy_on_push: true
source_dir: api
routes:
- path: /api
But when I try to execute
doctl apps create --spec .do/app.yaml
It returns a 500 Error and nothing else. I've tried executing the command both in a Github action and locally with different API tokens.
I'm able to access other resources on my DO account but I can't successfully create the spec.
This is the specific error I get back from doctl:
Error: POST https://api.digitalocean.com/v2/apps: 500 Server Error
Do y'all what could be going wrong?
So I discovered what was going wrong. Essentially the branch name was wrong (I put main instead of master).
You can find more info here: https://github.com/digitalocean/doctl/issues/883.
TLDR - this is the right config:
name: unique-expressions
services:
- name: api
environment_slug: node-js
github:
repo: Valencian-Digital/unique-expressions
branch: master
deploy_on_push: true
source_dir: api
routes:
- path: /api

Python CRON google flexible app engine not working

I have the following cron.yaml:
cron:
- description: "TEST_TEST_TEST"
- url: /cronBatchClean
- schedule: every 2 minutes
And then in app.yaml:
service: environ-flexible
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app
runtime_config:
python_version: 3
With this as main.py:
from flask import Flask, request
import sys
app = Flask(__name__)
#app.route('/cronBatchClean')
def cronBatchClean():
print("CRON_CHECK", file=sys.stderr)
return "CRON_CHECK"
When I type in the full URL, I receive "CRON_CHECK" on screen but this doesn't seem to be executing. Also in App Engine dashboard, when I click on CRON jobs there aren't any listed.
Any help in getting this to execute would be much appreciated,
Thanks :)
EDIT 1
I now have the cron task executing but I'm receiving a 404 error. When I type the full URL (that is - https://.appspot.com/cronBatchClean) the respective code executes.
I added a GET handler but I'm still not receiving any luck.
#app.route('/cronBatchClean', methods=['GET'])
def cronBatchClean():
print("CRON_JOB_PRINT", file=sys.stderr)
return "CRON_CHECK"
In the cron.yaml there are unnecessary “-” characters, that are starting the new list. YAML Syntax
Correct format for Cron Jobs cron.yaml, see Google Cloud documentation:
cron:
- description: "TEST_TEST_TEST"
url: /cronBatchClean
schedule: every 2 minutes
To deploy Cron Job use gcloud command :
$ gcloud app deploy cron.yaml
To solve this problem i changed the service name to default then i deploy with the default service the cron job task path was pointed to the default path of app engine so that when the task was scheduled 404 error raised because the path doesn't match when the service name set to "environ-flexible"
In app.yaml
change :
service: environ-flexible
to
service: default

Google app engine cron returning 404 for node js

I am trying to run a cron in google app engine which should run a node.js script every 2 minute but i always get 404 error in the log. I see the cron is running every 2 minute but its not finding the script cronRun.js. Below is the relevant part of the code.
cron.yaml
cron:
- description: "daily summary job"
url: /task
schedule: every 2 minutes
app.yaml
runtime: nodejs
env: flex
api_version: 1
threadsafe: true
handlers:
- url: /task
script: cronRun.js
log:
"GET /task" 404
By this I see that I am not defining the path correctly.
Below is the file structure
Have you tried making a request to the /task endpoint directly, without going through the Cron job?
The problem may be related to the application itself and not the Cron job, so I would recommend you to test it by accessing your App Engine application with the /task endpoint.
If it does not work, the issue is definitely caused by the application and not Cron.

Resources