开发者

Channels and TaskQueues in Google App Engine (client debugging)

开发者 https://www.devze.com 2023-02-09 03:29 出处:网络
I\'m trying to build and debug my first GAE application and have already benefited from the awesome support of Stackoverflowers to get where I am in having tasks being processed on the default queue.

I'm trying to build and debug my first GAE application and have already benefited from the awesome support of Stackoverflowers to get where I am in having tasks being processed on the default queue. Thanks!

However, I wanted to use Queues to demonstrate how you would do some 'long' work in the background. My idea was:

  1. Receive a request to process a large file.
  2. Store the file and enqueue a task.
  3. Return the response.
  4. Process the file on the background.
  5. Let the client know, via a Channel, that the work is done!

I have all this working but for one problem. On my development server the Task Queue doesn't seem to process tasks in the background. To simulate long running work I just popped a sleep in there.

def post(self):
    time.sleep(60)
    #use a channel to let the client know we're done

It appears that the GAE development server is single threaded. It doesn't respond at all until the item has been processed off the queue? Is this assumption right? Any ideas?

Thanks

Adding code exanples:

#code to enqueue task
taskqueue.add(url='/processSubmission', params={'key': activity.key() }, transactional=False)

#class that processes queued work
class ProcessSubmission(webapp.RequestHandler):
  def post (self):
    time.sleep(60)
    activity = db.get(db.Key(encoded=self.request.get('key')))
    activity.approved = True
    activity.put()
    channel.send_message(activity.userid, 'Wahoo! we are done'开发者_如何学Python)


Yes, the App Engine dev_appserver is single-threaded, and only processes a single request at a time. Your user-facing request should return before it begins processing the task queue request, however.

0

精彩评论

暂无评论...
验证码 换一张
取 消