【问题标题】:Cronjob on App Engine results in a Method Not Allowed error (405)App Engine 上的 Cronjob 导致 Method Not Allowed 错误 (405)
【发布时间】:2016-05-12 18:56:59
【问题描述】:

我正在尝试使用 Endpoints 在 App Engine 上运行 cronjob

我在使用 cronjob 时收到 Method Not Allowed (HTTP 405) 错误。如何解决此错误?

这是我目前的cron.xml

<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
    <cron>
        <url>/_ah/spi/messaging/v1/checkUpdates</url>
        <description>Check for news every 5 minutes</description>
        <schedule>every 5 minutes</schedule>
    </cron>
    <cron>
        <url>/_ah/spi/package.backend.MessagingEndpoint.checkUpdates</url>
        <description>Check for news every 5 minutes</description>
        <schedule>every 5 minutes</schedule>
    </cron>
</cronentries>

没有代码主体的我的端点:

@ApiMethod(
        name = "checkUpdatesPost",
        httpMethod = ApiMethod.HttpMethod.POST
)
public void checkUpdatesPost() {
    checkUpdates();
}

@ApiMethod(
        name = "checkUpdates",
        httpMethod = ApiMethod.HttpMethod.GET
)
public void checkUpdates() {
    // ... Stuff
}

通过Google APIs Explorer 运行这些函数中的任何一个都可以正常运行:

使用GET进行测试

GET https://myapp.appspot.com/_ah/api/messaging/v1/checkUpdates

使用POST进行测试

POST https://myapp.appspot.com/_ah/api/messaging/v1/checkUpdatesPost

这是日志,在Logs Viewer 上看到:

您可以在这里看到AppEngine-. 指的是 Cron 的尝试。 Chrome 48 是我的浏览器/Google APIs Explorer 的尝试。

据我了解,Cron POST 一起使用。为此,我为GET 创建了另一个函数,它反映了POST 的函数。

在我的cron.xml 中,我提供了两种变体。

  1. /_ah/spi/messaging/v1/checkUpdates - 这是我在浏览器中用来访问资源的内容。
  2. /_ah/spi/package.backend.MessagingEndpoint.checkUpdates - 这是我在浏览器中运行 #1 后在日志查看器中看到的内容。

【问题讨论】:

    标签: google-app-engine cron google-cloud-endpoints


    【解决方案1】:

    documentation中似乎有明确说明。

    调用 Google Cloud Endpoints

    您不能从 cron 作业调用 Google Cloud Endpoint。相反,你 应该向由处理程序服务的目标发出请求,该处理程序是 在应用程序的配置文件或调度文件中指定。那 然后处理程序调用适当的端点类和方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-08
      • 2013-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-26
      • 2021-12-12
      • 1970-01-01
      相关资源
      最近更新 更多