def get(self): from furious.async import Async from furious import context count = int(self.request.get('tasks', 5)) # Create a new furious Context. with context.new() as ctx: # Set a completion event handler. log = Log() log.put() ctx.set_event_handler('complete', Async(context_complete, args=[ctx.id, log.key.id()])) # Insert some Asyncs. for i in xrange(count): queue = 'a-worker-1' if i % 2 == 0: queue = 'z-worker-2' ctx.add( target=async_worker, queue=queue, args=[ctx.id, i, log.key.id()]) logging.info('Added job %d to context.', i) # When the Context is exited, the tasks are inserted (if there are no # errors). logging.info('Async jobs for context batch inserted.') message = "Successfully inserted a group of %s Async jobs." % str(count) self.response.out.write(message)