how to set cron job with http-post on google-app-engine? - java

I have set a google-cloud cron job like this:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/match</url>
<description>bla bla</description>
<schedule>every 2 minutes</schedule>
</cron>
</cronentries>
but i see in the google cloud console it sends a "get"
how can i change it to "post" ?

You can't. From Scheduling Tasks With Cron for Java (emphasis mine):
A cron job invokes a URL, using an HTTP GET request, at a given
time of day. An cron job request is subject to the same limits as
those for push task queues.
If you really, really need a POST you can trigger one from inside your cron job itself.

Related

How to make a cron job in App Engine that targets a service and a version?

I want to have a cron job that calls my endpoint at a certain services and version (App Engine).
I have created a cron job with the following config:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/CleanupRealtimeDatabase</url>
<target>dev-dot-admin</target>
<description>Cleanup Realtime Database (Dev)</description>
<schedule>every 24 hours</schedule>
</cron>
</cronentries>
This will make a call to http://dev-dot-admin.myapp.appspot.com/CleanupRealtimeDatabase
This doesn't work, because it can not combine the -dot- and the .
So the only solution is to use -dot- twice or use . twice. I can't control the second dot in the url (it's not part of the config). But when I change the dot to . in my config above I get the following error:
Bad configuration: XML error validating
/CleanupRealtimeDatabase
dev.admin
Cleanup Realtime Database (Dev)
every 24 hours
against /Users/user/sdk/google-cloud-sdk/platform/google_appengine/google/appengine/tools/java/docs/cron.xsd
Caused by: cvc-pattern-valid: Value 'dev.admin' is not facet-valid
with respect to pattern '[a-z\d-]{1,100}' for type 'target-Type'.
Not sure how to solve this? It feels like a bug in App Engine tooling.
This won't work as the (single) service version that will receive the targeted cron requests is not under the cron configuration control. From the row in the Cron job definitions (emphasis mine):
The target string is prepended to your app's hostname. It is
usually the name of a service. The cron job will be routed to the
version of the named service that is configured for traffic.
Warning: Be careful if you run a cron job with traffic splitting enabled. The request from the cron job is always sent
from the same IP address, so if you've specified IP address splitting,
the logic will route the request to the same version every time. If
you've specified cookie splitting, the request will not be split at
all, because there is no cookie accompanying the request.
If the service name that is specified for target is not found, then the Cron request is routed to either the default service, or to
the version of your app that is configured to receive traffic. For
more information about routing, see How Requests are Routed.
But since the cron service is nothing more than GET requests sent according to the schedule you could have a single generic cron config and, inside its handler, issue yourself more specific HTTP(S) requests to any URLs you desire.
You could use the apps.services.versions API in order to dynamically build the correct list of these per service-version pair URLs.

GAE cron job shuts down unexpectedly

I have some cron jobs configured in cron.xml in an application on Google App Engine.
These jobs work once a day on a version of my application and make some work on the db.
For example a cron job calls v1.myapp.appspot.com...
After some weeks this application instance seems to no longer work correctly. It does not execute the cron jobs as I expect.
On GAE Dashboard I found a section with a list of cron job, but I can't see my cron jobs there.
Why did they disapper? What's wrong with my configuration environment? or Why google stops the execution of my cron jobs?
The cron job configuration is an app-wide scope configuration, it's not a configuration of a specific service/version. Every cron deployment (which can be done without necessarily updating a service/version) will overwrite the previously deployed one.
To avoid accidental errors personally I have a single cron config file at the app level, symlinked inside each service as needed.
If you want to keep the cron job for an older version running you need to add a configuration entry for it with a target matching that service/version, otherwise the cron job will stop working when that version is no longer the default one (as the cron-triggered requests will be directed towards the default service/version):
From Creating a cron job:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/tasks/summary</url>
<target>beta</target>
<description>daily summary job</description>
<schedule>every 24 hours</schedule>
</cron>
</cronentries>
The target specification is optional and is the name of a
service/version. If present, the target is prepended to your app's
hostname, causing the job to be routed to that service/version. If no
target is specified, the job will run in the default version of the
default service.

Monitor google app engine cron jobs in console?

This might be a dumb question, but, i just can't find cron jobs panel, I've got an app in java and I need to refresh the data every day, so I create this cron.xml inside WEB-INF:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/refreshdata</url>
<description>Daily data refresh cron task </description>
<schedule>every day 05:00</schedule>
</cron>
</cronentries>
I deployed it, but it doesnt work and I cant find the "cron job panel" in console to monitor it or even check if GAE recognizes it...
Documentation says " (You can verify the Cron job you just deployed by clicking Cron Jobs in the left nav pane.) http://i.stack.imgur.com/1niVt.png "
but it doesn't exist anymore, gae's console UI changed, where it is now? I tried in logs without success
it is something wrong with my .xml?
Any help would be apreciated, thanks.
If you are using the new Console for your projects in app engine then this is how it will look like after you have selected a project to view from https://console.developers.google.com/project using your google account.
Hope it helps!
You can find it under Task Queues, you should be able to see Cron as a tab in that view
On Cloud developers console, it should be available at this location:
https://console.developers.google.com/project/your-project-id/appengine/taskqueues?tab=CRON

GAE : How to configure backends.xml for long time working process

In my java application i'm processing one lack data per day using cron job but it cannot be properly do with cron jobs (DeadLineExceedException) and 10 minute is not enough to complete the process. So i would like switch the process to backends.xml. But i don't know how to move backends.xml. How can i start the process at a fixed time after moving to backends.
If I understand it correctly, you want your Cron jobs to be executed at your backend in order to have a longer deadline in processing jobs. You can add <target>[backend_version]</target> on the cron job definition in your cron.xml in order to have the cron executed at a specific version of your app.
Combined with your backends.xml file, this means that you could configure both files as per the following examples:
backends.xml
<backends>
<backend name="longtimeworker">
<class>B1</class>
<instances>1</instances>
</backend>
and
cron.xml
<cronentries>
<cron>
<url>/longtimeworkingprocesshandler</url>
<schedule>every 12 hours</schedule>
<target>longtimeworker</target>
</cron>
That way, you can configure your cron to be executed at the longtimeworker backend.

running a cron job just once

how can we schedule a cron job to run just once on google app engine for java?
i tried to set a very large value like every 1000 years but doesnt seems to work.
any other option? syntax used is:
<cron>
<url>/AdHocScriptJob</url>
<description>Run adhoc script</description>
<schedule>every 200 minutes</schedule>
<timezone>Asia/Calcutta</timezone>
</cron>
i tried to look at https://developers.google.com/appengine/docs/java/config/cron
That's what task queues are for: https://developers.google.com/appengine/docs/java/taskqueue/overview
Alternatively, you may delete the cron configuration after the task executes or make your code idempotent (e.g. by mixing it with a pull queue).

Categories