在appengine中我创建了一个cron作业,它在间隔2分钟后执行并将一些数据发布到我的Facebook墙上。
但是每隔两分钟我看到后面的日志就会显示以下行,
This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application.
我的脸书墙上没有发布任何内容。
但是当我手动执行cron job url(通过直接在浏览器中点击)时,应用程序会在我的墙上发布一些内容。
这是我的app.yaml
,
application: thisisreallyappname
version: 1
runtime: python27
api_version: 1
threadsafe: yes
builtins:
- remote_api: on
inbound_services:
- warmup
libraries:
- name: django
version: latest
handlers:
- url: /_ah/queue/deferred
script: djangoappengine.deferred.handler.application
login: admin
- url: /_ah/stats/.*
script: djangoappengine.appstats.application
- url: /media/admin
static_dir: django/contrib/admin/media
expiration: '0'
- url: /static/admin
static_dir: django/contrib/admin/static/admin
expiration: '0'
- url: /static
static_dir: static
expiration: '0'
- url: /.*
script: djangoappengine.main.application
这是我的urls.py
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^crona/$', 'testapp.views.crona', name='crona'),
url(r'^admin/', include(admin.site.urls)),
)+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
这是观点,
def crona(request):
logging.info("hello")
croned=CronEntries.objects.all().order_by('posted_datetime')[0]
if croned.email_id=='n*******@gmail.com':
try:
access_token="##############################################################"
graph = facebook.GraphAPI(access_token)
graph.put_object("me", "feed", message=croned.status_cron)
croned.delete()
except Exception as e:
logging.info(e)
else:
return HttpResponse("ok")
这是cron.yaml
cron:
- description: post on fb
url: /crona
schedule: every 2 minutes
答案 0 :(得分:2)
您的网址处理程序url(r'^crona/$', ...
需要一个尾部斜杠,您的cron网址会省略。即使您将应用设置为附加尾部斜杠,也不要使用cron或taskqueue执行此操作,因为您希望它们返回200
,而不是301
。< / p>