用于 python 脚本的 Google Cloud app.yaml cron.yaml 不起作用但没有日志 [英] Google cloud app.yaml cron.yaml for python script not working but no log

查看:14
本文介绍了用于 python 脚本的 Google Cloud app.yaml cron.yaml 不起作用但没有日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Google Cloud 的 cron 每隔一段时间运行我的 Python 脚本.我按照 https://cloud.google.com/appengine/中的说明进行操作docs/standard/python/config/cron 设置所有内容,任务显示在我的任务队列中用于 cron 作业,但是当我单击运行时,状态显示失败.日志中也没有显示任何内容(当我单击日志下的查看"时,它显示未找到任何条目",因此我无法判断自己做错了什么.我查看了一些类似的问题,似乎我应该使用更多处理程序,但我不确定何时需要处理程序.脚本 (scraper.py) 与 cron.yaml 和 app.yaml 位于同一目录中,我的代码如下.感谢任何帮助!

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

推荐答案

你不能直接从 GAE cron 运行像你的 scraper.py 这样的普通 python 脚本,至少不能用它的当前内容.

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

其中需要一个基本的 GAE 应用程序框架,以及用于 cron 作业 URL 的处理程序.请记住,GAE cron 作业只是对该 URL 的 GET 请求,您的应用程序需要处理该请求.该处理程序是您放置要执行的代码的地方.

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.

您可以在Hello World 代码审查.

这篇关于用于 python 脚本的 Google Cloud app.yaml cron.yaml 不起作用但没有日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆