3

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!

Jenni
  • 63
  • 2
  • 9
  • Do you have a `JSONdownload.app`? – dirn Aug 20 '17 at 00:11
  • I have a JSONdownload.py - I've moved things around a little and I can at least call and run the script from a view... I'm thinking next I *should* be able to call from cron? If I can do that? – Jenni Aug 20 '17 at 00:22

2 Answers2

1

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.

Dan Cornilescu
  • 37,297
  • 11
  • 54
  • 89
0

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.

Jenni
  • 63
  • 2
  • 9