【问题标题】:When setting up app.yaml url handler, how to format url to script?设置 app.yaml url 处理程序时,如何将 url 格式化为脚本?
【发布时间】:2015-08-18 09:31:41
【问题描述】:

我不确定如何在 app.yaml 中为处理程序的脚本设置 URL。我尝试按照文档 (https://cloud.google.com/appengine/docs/python/config/cron) 设置 cron 作业,但我的 cron 在 GAE 中失败。我也收到此错误: \myproject\app.yaml: threadsafe cannot be enabled with CGI handler: myprojectApp/dsProcess.aggregate

我认为文档假设我没有使用 WSGI,但我对 WSGI 的使用在某种程度上影响了脚本在应用程序中的访问方式。

这是我的项目结构和相关文件:

myproject/
    myproject/      (package for project)
        urls.py     (defers url handling to myprojectApp.urls)
    myprojectApp/   (package for actual app)
        urls.py
        dsProcess.py  ( contains the aggregate function my cron should call)
    app.yaml
    cron.yaml
    main.py

在 app.yaml 中,我不确定如何将 url 格式化为 dsProcess.py 的聚合函数:

app.yaml

handlers:
- url: /aggDB
  script: myprojectApp/dsProcess.aggregate <-- unsure here

应该改为 myprojectApp.dsProcess.aggregate 吗? myprojectApp.dsProcess.aggregate.py? myprojectApp.dsProcess.aggregate.app?

我正在运行 Python 2.7.9

cron.yaml

cron:
- description: aggregates db
  url: /aggDB
  schedule: every 1 mins

ma​​in.py

import django.core.handlers.wsgi    
application = django.core.handlers.wsgi.WSGIHandler()

myprojectApp/dsProcess.py

def aggregate():

myproject/urls.pymyprojectApp/urls.py

我猜我不需要在其中为将被命中的aggDB/ url 设置 url 模式,因为app.yaml 将为我注册并监听该 url 模式。这是正确的吗?

不过,这里有两个 urls.py:

myproject/urls.py

urlpatterns = patterns('',
                       (r'^', include('myprojectApp.urls')),
                       )

myprojectApp/urls.py

urlpatterns = patterns('',
    ...
     #don't need to handle this here, let app.yaml handle it?  
    # (r'^aggDB/$', dsProcess.aggDStoJSON()),
)

我使用 wsgi 会影响我访问脚本的方式吗?如果是这样,如何以及为什么?

【问题讨论】:

    标签: python django google-app-engine cron wsgi


    【解决方案1】:

    这是一个 Python 路径,你使用点而不是斜线。

    但 cron URL 并没有什么特别之处:它们与您项目中的任何其他 URL 完全相同,并且遵循完全相同的规则。如果您希望它由 Django 处理,则根本不需要在 app.yaml 中添加特定条目,只需让它使用其余 Django URL 的现有映射即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-06
      • 1970-01-01
      • 2011-07-31
      • 1970-01-01
      • 2019-10-18
      相关资源
      最近更新 更多