【问题标题】:GAE Task Queue: Task not running/outputtingGAE 任务队列:任务未运行/输出
【发布时间】:2011-07-28 14:40:27
【问题描述】:

我已经开始使用任务队列来安排一个耗时的任务在后台运行。我要运行的任务在 URL '/test' 中,而我用来安排任务的 URL 是 '/bgtest'。这是“/bgtest”的处理程序:

class RunTestAsBackgroundProcess(BaseHandler):
def get_secure(self):
    taskqueue.add(url='/test', method='GET')
    logging.debug("Task added to queue")
    return

“/test”任务将数据输出到日志中,当我正常访问/test时,它会执行,完成,我可以在日志中找到结果。但是,当我运行 /bgtest 时,除了来自上述函数的“任务添加到队列”消息之外,我在日志中什么也看不到。奇怪的是,在管理控制台的任务队列中,它说有一个任务在最后一分钟运行,但没有给我任何关于它的细节。有什么想法吗?

编辑:只是为了解释代码,BaseHandler 是我用来检查用户是否登录到 Facebook 的超类,get_secure() 是在超类的 get() 方法之后调用的方法。

编辑:/test 运行这个类:

class CalculateTestAllocations(BaseHandler):
def get_secure(self):
    dbuser = db.GqlQuery("SELECT * FROM User WHERE fbid = :1", self.user['uid'])[0]
    if (dbuser.isadmin != True):
        self.redirect('/')

    #test data
    drivers = []
    passengers = []

    drivers.append(allocation.Driver("01", allocation.Location(51.440958, -2.576318), 3, 1000)) # coming from Bristol
    drivers.append(allocation.Driver("02", allocation.Location(55.935628, -3.285044), 3, 1000)) # coming from Edinburgh

    passengers.append(allocation.Passenger("03", allocation.Location(51.483193, -3.208187), 1000)) # coming from Cardiff
    passengers.append(allocation.Passenger("04", allocation.Location(52.469263, -1.860303), 1000)) # coming from Birmingham
    passengers.append(allocation.Passenger("05", allocation.Location(53.783703, -1.541841), 1000)) # coming from Leeds
    passengers.append(allocation.Passenger("06", allocation.Location(54.973994, -1.636391), 1000)) # coming from Newcastle

    logging.debug("Running allocation engine now (GET)")

    alloc = allocation.Allocation()
    alloc.buildProblem(drivers, passengers, allocation.Location(52.951923, -1.169967)) # destination at Nottingham
    alloc.solveAndOutput()

这会为我的分配算法填充一组测试数据(该算法接收一组驾驶员和乘客并为他们计算最佳路线),然后告诉算法运行。发送到日志的内容包含在 allocation.solveAndOutput() 方法中,该方法执行以下操作:

def solveAndOutput(self):
    routes = self.solveProblem()
    logging.warn("Num routes: "+str(len(routes)))
    logging.warn("Length of first route: "+str(len(routes[0])))
    for route in routes:
        print self.getStaticMapAddress(route)
        logging.debug(self.getStaticMapAddress(route))

正如我所说,如果我只运行 /test 我会得到这些输出,但如果我运行 /bgtest 什么都不会发生,但是任务队列说它在过去一分钟内运行了一些东西。

【问题讨论】:

  • 如果您将日志设置为显示所有内容,您会在日志中看到什么? /test 有对应的日志条目吗?它的状态码是什么?
  • 当我运行 /test 时,我得到状态码 200,以及我为 /test 设置的所有日志条目以输出。当我运行 /bgtest 时,我没有得到 /test 获得的任何日志条目
  • /test 有什么作用?请添加那部分代码。
  • @benwad 您是否将日志设置为“所有请求”?日志中显示了什么?
  • @Nick 切换到“所有请求”并看到当我运行 /bgtest 时它输出了“任务添加到队列”消息,然后我看到它向 /test 发出了一个状态为 200 的请求,但没有记录。另外,它说它只花了 3 毫秒,而当我直接运行 /test 时,它最多需要 1000 毫秒。

标签: python google-app-engine scheduled-tasks


【解决方案1】:

看起来您的 /test 脚本正在从我只能假定为会话的内容中获取,然后基于此进行重定向。这显然不适用于任务队列任务 - 没有用户,因此没有会​​话。

【讨论】:

  • 已排序。你是对的 - 我只需要删除任何需要用户的东西,即 BaseHandler 继承。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多