3

I'm trying to use Google cloud's cron to run my Python script at a time interval. I followed instructions from https://cloud.google.com/appengine/docs/standard/python/config/cron to set up everything and the task shows up in my Task Queue for cron jobs, but when I click run the status says failed. Nothing shows up in the log either (when I click "View" under log it says "no entries found" so I can't tell what I'm doing wrong. I looked at some similar questions and it seems like I should be using more handlers but I'm not sure when handlers are needed. The script (scraper.py) is in the same directory as cron.yaml and app.yaml and my code is below. Any help appreciated!

scraper.py

import requests
from bs4 import BeautifulSoup
import datetime
from firebase.firebase import FirebaseApplication

cron.yaml

cron:
- description: daily update
  url: /
  schedule: every 24 hours

app.yaml

runtime: python27
api_version: 1
threadsafe: true

handlers:
- url: /
  script: scraper.app
2
  • In the Task Queue viewer, click the "cron jobs" tab. To the left of the "Run" button is a "View" button. What does the error show? If it's a 404, then you aren't handling the url properly. If a 500, then some code error. How are you handling the urls in scraper? And, you probably want a wildcard url handler in app.yaml: ` - url: /.*` instead of ` - url: /` Commented Jul 1, 2017 at 1:19
  • When I click "View" it says "no entries found" so I don't see any errors logged, just that the status is failed. Everything in scraper I just used pip install. I changed it to the wildcard url and it's still not working, but thanks for the input. Commented Jul 1, 2017 at 6:55

1 Answer 1

1

You can't run a plain python script like your scraper.py directly from the GAE cron, at least not with its current content.

You need a basic GAE app skeleton in there, with a handler for the cron job's URL. Remember that the GAE cron job is simply a GET request for that URL, which your app needs to handle. That handler is where you'd place the code you want to be executed.

You can find a sample skeleton in the Hello World code review.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.