GAE 任务队列:任务未运行/输出
我开始使用任务队列来安排时间密集型任务在后台运行。我想要运行的任务位于 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()
这将为我的分配算法填充一组测试数据(该算法接收一组司机和乘客并计算他们的最佳路线),然后告诉算法运行。发送到日志的内容包含在 allocate.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 什么也不会发生,但任务队列会说它在过去的一分钟里跑过一些东西。
I've started using the task queue to schedule a time-intensive task to run in the background. The task I want to run is in the URL '/test', and the URL I am using to schedule the task is '/bgtest'. Here is the handler for '/bgtest':
class RunTestAsBackgroundProcess(BaseHandler):
def get_secure(self):
taskqueue.add(url='/test', method='GET')
logging.debug("Task added to queue")
return
The '/test' task outputs data to the logs, and when I visit /test normally it executes, finishes and I can find the results in the logs. However, when I run /bgtest I see nothing in the logs except the "Task added to queue" message from the above function. Strangely, in the Task Queue in the admin console it says that a task has run in the last minute but doesn't give me any details about it. Any ideas?
EDIT: Just to explain the code, BaseHandler is a superclass I use to check the user is logged in to Facebook, and get_secure() is the method called after the superclass' get() method.
EDIT: /test runs this class:
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()
This populates a set of test data for my allocation algorithm (which takes in a set of drivers and passengers and calculates the optimum route for them) and then tells the algorithm to run. The stuff sent to the log is contained in the allocation.solveAndOutput() method, which does this:
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))
As I said, if I just run /test I get these outputs, but if I run /bgtest nothing happens but the task queue says it ran something in the past minute.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您的
/test
脚本是从我只能假设是会话的内容中获取,然后基于该会话进行重定向。这显然不适用于任务队列任务 - 没有用户,因此没有会话。It looks like your
/test
script is fetching from what I can only presume is a session, and then redirecting based on that. That's obviously not going to work in a Task Queue task - there is no user, and hence no session.