1

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.

6
  • What do you see in the logs if you set them to show everything? Is there a corresponding log entry for /test? What is its status code? Commented Apr 3, 2011 at 12:43
  • When I run /test I get status code 200, and all the log entries I have set for /test to output. When I run /bgtest I don't get any of the log entries I get with /test Commented Apr 3, 2011 at 14:37
  • What does /test do? Please, add that part of code. Commented Apr 3, 2011 at 15:45
  • @benwad Did you set the logs to 'all requests'? What shows up in the logs? Commented Apr 3, 2011 at 23:36
  • @Nick switched to 'all requests' and saw that when I ran /bgtest it outputted the "Task added to queue" message, then I see it made a request to /test with a 200 status, but nothing logged. Plus it says it only took 3ms, whereas when I run /test straight out it takes up to 1000ms. Commented Apr 4, 2011 at 0:09

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorted it. You were right - I just needed to remove anything that requires a user, i.e. that BaseHandler inheritance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.