404 from cron job on google app engine django app

2020-04-11 18:06发布

So, everything else works... to preface this. But, I haven't really moved outside the admin interface. I'm trying to get data from an API and insert it into the database if there's changes. I've managed to write a script that can do that (in theory... it can do it locally), but I can't get the app in the cloud to recognize its existence. I've followed Google's suggestion of adding it to the app.yaml and cron.yaml to no avail.

Do I need to add this to a urls.py? I haven't mucked with teh handlers at all thus far and I'm not sure what settings.py makes happen, what the yaml files make happen, and how much of this is pixie dust.

here are teh relevant files... app.yaml

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT mysite.wsgi
threadsafe: yes

beta_settings:
    cloud_sql_instances: [redacted]

runtime_config:
  python_version: 3

health_check:
  enable_health_check: False

handlers:
- url: /static
  static_dir: static/
- url: /run/get_data/
  script: JSONdownload.app
  login: admin
- url: .*
  script: mysite.wsgi.application

cron.yaml

cron:
- description: "get data"
  url: /run/get_data/
  schedule: every 5 minutes

JSONdownload.py

#!/usr/bin/env python
# /var/spool/cron/crontabs
import json
import urllib2

from django.http import HttpResponse
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

from .models import Game
from .models import Team


class JSONdownloadHandler(webapp.RequestHandler):
    def get(self):
        self.response.write('cron')
class MainHandler(webapp.RequestHandler):
    def get(self):
        self.response.write('yay')

I'm finding great resources for a basic python app... but none for this situation really... anyone know of something better than what I'm doing, PLEASE let me know!

2条回答
Root(大扎)
2楼-- · 2020-04-11 19:09

So... it was that I didn't route to teh location. I was actually able to just set a route (with admin against it) to the URL and then able to call it via the cron.yaml.

查看更多
走好不送
3楼-- · 2020-04-11 19:13

You're mixing up elements of the flexible environment app.yaml with those of the standard environment app.yaml

In particular the script: JSONdownload.app portion is ignored. You need to add the handler for the /run/get_data/ path inside your mysite.wsgi app, maybe from there invoking the JSONdownload.py code.

Somehow related: cron job in google app engine not working.

查看更多
登录 后发表回答