GAE Task Queue: Task not running/outputting
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(l开发者_如何学Pythonen(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.
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.
精彩评论