问题
I have developed a backend using Google App engine and Endpoints API. One of Api Method is a job that should run every X hours and do some logical stuff.
my Question is how can I call this api method using Cron Job.
I know the URL of the Api Method and i even succeed call her using the browser. but when I try call it with the cron job, the job was failed with 404 error code.
here the cron.xml:
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/_ah/api/meetingMatchingEndpoint/v1/matchingProcess</url>
<description>Matching process</description>
<schedule>every 1 minutes</schedule>
</cron>
</cronentries>
when I try call it from the browser and succeed I wrote the full URL:
https://acadden-motif-344.appspot.com/_ah/api/meetingMatchingEndpoint/v1/matchingProcess
回答1:
Google Cloud Endpoints are architected in a manner such that they provide you a well designed REST layer over your actual code.
Having said that, I think that since the Cron Job is also running inside of the same application, you should ideally not go through the route of invoking the REST API URL. Instead you should directly invoke your functionality through well designed Java classes that encapsulate the functionality you want to invoke.
回答2:
You can not specify urls starting with /_ah/api
in cron.xml
as they do not reside directly in your application, rather they are part of Google's API infrastructure, and therefore calls to the API do not come to your application,so your application won't receive those requests.
Work around :
Replicate the behavior of your API in a servlet may be and register that in your cron.xml file.
来源:https://stackoverflow.com/questions/23438289/use-cron-jobs-with-appengine-endpoints-api