Google App Engine Cron not triggering endpoint at specific times - google-app-engine

We have multiple App Engine Cron entries triggering our App Engine application, but recently we detected a decrease on the number of the processed events handled by one of the endpoints of our application. By looking at the App Engine Cron logs for this specific Cron entry on StackDriver, we found out that, during the days we invesgated (March 11-15), that are missing entries. Most of the missing triggers coincide through the days (12:15, 14:15, 16:15, 18:15, 20:15, 22:15, 00:15).
The screenshot below displays one specific day, and the red lines indicate the missing entries:
There are no requests with HTTP status code different than 200.
This is the configuration of the specific Cron entry (replaced some words with XXX due to business restrictions):
- description: 'Hourly job for XXX'
url: /schedule/bigquery/XXX
schedule: every 1 hours from 00:15 to 23:15
timezone: UTC
target: XXX
retry_parameters:
min_backoff_seconds: 2.5
max_doublings: 5
Could someone # GCP side take a look? The task name is 53751dd6a70fb9af38f49993b122b79f.

it seems like if the request takes longer than an hour, then the next one gets skipped (i.e. cron doesn't launch the next iteration if the current iteration is still running)
maybe do the actual work in a separate task and then the only thing the cron task does is launch this separate task

Related

StackDriver is alerting even when policy is met

I have a Cron job setup on Google App Engine, that runs everyday at 11 am.
Given that the execution of the cron is crucial to my system, I decided to setup an alert for it if there's any failures, and this was setup as:
Create a metric with
Resource Type: GAE Application
Metric: Response Count
And filters:
Response Code >= 200
Response Code <= 299
Module ID: my-application
With an empty Group By and Aggregator set to NONE
Condition triggers if any time series violates condition is absent for 1 day
So my intended behavior was "If this app doesn't respond 200 at the cron for 1 day (enough for it to be hit), alert me"
But I'm getting an email with the alert almost daily.
Is this a bug? Or is there another way to set this up? I'm receiving an alert, and when I see the cron page at App Engine, it was ran on the correct time, and returned 200 (success).

Cron job without scheduling in Google App Engine

I would like to create a cron job in GAE but I do not want it to be scheduled.
I would like to call it manually whenever I need it.
What should I put in the schedule element?
From Scheduling Tasks With Cron for Python:
A cron job makes an HTTP GET request to a URL as scheduled. The
handler for that URL executes the logic when it is called.
So, as #snakecharmerb mentioned, you have to create that handler doing whatever you want the cron job to do and map it to the desired cron url.
In order to avoid scheduling you simply don't upload the cron configuration, instead you manually trigger the job by making that same GET request that the scheduler would otherwise do, for example using curl:
curl https://your_app.appspot.com/cron_handler_url
You can also do something like
schedule: every 99999 hours
That way, its almost like 11 years so you know that cron won't be triggered till then.
Before reading, this is slightly hacky although it does work.
I needed something similar to this, primarily due to the need for a slightly longer processing time than 60 seconds.
In my cron.yaml I specified:
- description: My example cron
url: /cron/my/example/cron
schedule: 25 of dec 12:00
Then within my handler I check if the date is the 25th december and abandon the request.
This seems to be the only way to have a 'manual' cron.
In Python this is simple to check the date.
from datetime import datetime
import logging
now = datetime.utcnow()
if now.day == 25 and now.month == 12:
logging.info("Skipping as it's the 25th December")
return

Google app engine cron scheduler is not using synchronized

I want to run a cron for every 2 minutes interval, 0,2,4,6,8 .... each cron execution runs for 2 minutes.
I configured cron schedule with synchronized as below. But I still see scheduler is behaving as if synchronized not given.
Crons are scheduled at
0-2 First cron
4-6 Second cron
8-10 third cron
Cron scheduler is waiting for 2 minutes after last cron execution.
If I understand synchronized correctly, it is added to avoid this behavior.
Why this happening.
<cron>
<url>/cron/syncPrices</url>
<description>Fetch data from source and cache it in data store.</description>
<schedule>every 2 minutes synchronized</schedule>
</cron>
You can check the actual cron configuration for your application on the old GAE console in the Cron Jobs menu on the left. You're looking to confirm if synchronized (or its from 00:00 to 23:59 equivalent) is present for the respective job:
if synchronized is missing it's possible that the cron.yaml file wasn't uploaded/updated during the regular app upload - I noticed this to be the case with my multi-module (python) application. You have to specifically update the cron configuration using the update_cron option of your AppCfg utility.
if synchronized is indeed present and the unexpected behaviour continues you should open a support case with Google.
FYI It looks like 'synchronized' is no longer part of the cron.yaml documentation. I've reached out to Google via the documentation feedback link.

Google App Engine sending mails on daily basis

I want to send mails on daily basis at 00:00 am using task queue, i can store a mail in a queue for 30 days at most. Now to make a task queue run do i need a corn job for it. Or the app engine will itself make the task run by itself.
And can i add a particular time for task queue to run like the corn job.
The App Engine Cron Service allows you to configure regularly
scheduled tasks that operate at defined times or regular intervals.
These tasks are commonly known as cron jobs. These cron jobs are
automatically triggered by the App Engine Cron Service. For instance,
you might use this to send out a report email on a daily basis, to
update some cached data every 10 minutes, or to update some summary
information once an hour.
A cron.yaml file in the root directory of your application (alongside
app.yaml) configures scheduled tasks for your Python application. The
following is an example cron.yaml file:
cron:
- description: daily summary job
url: /tasks/summary
schedule: every 24 hours
- description: monday morning mailout
url: /mail/weekly
schedule: every monday 09:00
timezone: Australia/NSW
- description: new daily summary job
url: /tasks/summary
schedule: every 24 hours
target: beta
https://cloud.google.com/appengine/docs/python/config/cron

How do I run a cron job on Google App Engine immediately?

I have configured Google App Engine to record exception with ereporter.
The cron job is configured to run every 59 minutes. The cron.yaml is as follows
cron:
- description: Daily exception report
url: /_ereporter?sender=xxx.xxx#gmail.com # The sender must be an app admin.
schedule: every 59 minutes
How to do I run this immediately.
What I am trying to do here is simulate a 500 HTTP error and see the stack trace delivered immediately via the cron job.
Just go to the URL from your browser.
You can't using cron. Cron is a scheduling system, you could get it to run every minute.
Alternately you could wrap your entire handler in a try/except block and try to catch everything. (You can do this for some DeadlineExceededErrors for instance) then fire off a task which invokes ereporter handler, and then re-raise the Exception.
However in many cases Google infrastructure can be the cause of the Error 500 and you won't be able to catch the error. To be honest you are only likely to be able to cause an email sent for a subset of all possible Error 500's. The most reliable way probably be to have a process continuously monitor the logs, and email from there.
Mind you email isn't consider reliable or fast so a 1 min cron cycle is probably fast enough.
I came across this thread as I was trying to do this as well. A (hacky) solution I found was to add a curl command at the end of my cloudbuild.yaml file that triggers the file immediately per this thread. Hope this helps!
Make a curl request in Cloud Build CI/CD pipeline

Resources