运行cron作业时遇到问题。 Cron作业总是在谷歌开发者控制台上显示失败,似乎没有办法找出原因。如果我使用网站appspot.com/crons/ftpcronjon它执行得很好。
这是我的代码:
import httplib2
import logging
import webapp2
from apiclient import discovery
from google.appengine.api import memcache
from oauth2client.appengine import AppAssertionCredentials
credentials = AppAssertionCredentials( scope='https://www.googleapis.com/auth/compute' )
HTTP = credentials.authorize(httplib2.Http(memcache))
compute = discovery.build('compute', 'v1', http=HTTP)
PROJECT_ID = "project-id"
INSTANCE = "json/rest body of instance parameters, this works"
class vmlaunchftp(webapp2.RequestHandler):
def __init__(self, request=None, response=None):
self.initialize(request, response)
def get(self):
request = compute.instances().insert(project=PROJECT_ID, body=INSTANCE, zone="us-central1-b" )
response = request.execute(http=HTTP)
APPLICATION = webapp2.WSGIApplication([('/crons/ftpcronjob', vmlaunchftp)], debug=True)
的app.yaml
application: sh-vo-001
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
#cron job
- url: /crons/ftpcronjob
script: vmlaunch.APPLICATION
#Endpoint handler
- url: .*
script: main.APPLICATION
libraries:
- name: pycrypto
version: latest
- name: endpoints
version: 1.0
- name: webapp2
version: "2.5.2"
cron.yaml
cron:
- description: vmlaunch.py
url: /crons/ftpcronjob
schedule: every day 11:30
timezone: America/Los_Angeles
我怀疑它失败了,因为来自request.exe的响应超时,但为什么它可以在网站上运行?
如何在不使用任务队列的情况下从appengine在VM上启动作业?
我们如何在没有足够实时更新日志文件的情况下调试此类问题?
编辑:添加了app.yaml,cron.yaml;适用于devserver,但凭据预期不好!