K
K
klinifini2012-08-04 22:32:09
Python
klinifini, 2012-08-04 22:32:09

How to organize task queue in AppEngine?

It would seem a simple task, but I'm already banging my head against the wall. Backend machine, there is a method that executes a task one by one, and if the task queue is empty, terminates.

from google.appengine.api import taskqueue
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class Worker(webapp.RequestHandler):
  def get(self):
    q = taskqueue.Queue('pull-queue')
    tasks = q.lease_tasks(3600, 1)
    if len(a):
      task = tasks[0]
      # долгая работа с задачей
    q.delete(task)

application = webapp.WSGIApplication([('/backend', Worker)])

Accordingly, the front-end machine simply puts the task at the end of the queue
q = taskqueue.Queue('pull-queue')
q.add(taskqueue.Task(payload=data, method='PULL'))

How to signal the backend that tasks have appeared in the queue? I should probably say that this is a dynamic backend, and there are situations when it is simply not running.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arthur, 2012-08-05
@ArthurG

Run backend periodically by cron.

X
xSkyFoXx, 2012-08-05
@xSkyFoXx

You can use asynchronous requests via url fetch .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question