简体   繁体   中英

Cron job not running with appengine

In appengine I have created a cron job which executes after 2 min of interval and post some data to my facebook wall.

But after every two minutes when I see logs in appengine it shows me following lines ,

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.

And nothing is posted on my facebook wall.

But when I manually execute cron job url (by hitting directly in the browser) , the application posts something on my wall.

Here is my 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

Here is my 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)

And here is view ,

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")

Here is cron.yaml

cron:
- description: post on fb
  url: /crona
  schedule: every 2 minutes

您的网址处理程序url(r'^crona/$', ...需要尾部斜杠,您的cron网址会忽略该斜杠。即使您将应用程序设置为添加尾部斜杠,您也不想使用cron做到这一点或任务队列,因为您希望他们返回200而不是301

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM