Use Cron jobs with Appengine Endpoints API

╄→гoц情女王★ 提交于 2020-01-24 00:31:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!