Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google cloud app.yaml cron.yaml for python script not working but no log

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
like image 880
mj99 Avatar asked Jan 21 '26 03:01

mj99


1 Answers

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.

like image 62
Dan Cornilescu Avatar answered Jan 23 '26 16:01

Dan Cornilescu