def do_work(self, shard_url, params=None, job_id=None, **kwargs): """ Task params are passed as params, additional kwargs passed to taskqueue api. """ # job_id prevents fork bomb on fanout; passed to shards job_id = job_id or base64.b32encode(uuid.uuid4().bytes).strip("=").lower() # first tier of shards shards = Shard.query(ancestor=self.key).filter(Shard.depth == 0).fetch(keys_only=True) params = params or {} params.update(dict(shard_url=shard_url, subscription=self.key.urlsafe()), job_id=job_id) for shard in shards: params.update(dict(shard=shard.urlsafe())) safe_enqueue(shard_url, params=params, name="%s-%s" % (job_id, shard.id()), **kwargs)
def do_work(self, shard_url, work_url, params=None, **kwargs): """ Task params are passed as params, additional kwargs passed to taskqueue api. params needs to have job_id in it which the parent task should have received. """ params = params or {} # job_id gets passed along params.update(shard_url=shard_url, work_url=work_url, subscription=self.subscription.urlsafe()) # kick off children for child in self.children: params.update(dict(shard=child.urlsafe())) safe_enqueue(shard_url, params=params, name="%s-%s" % (params["job_id"], child.id()), **kwargs) # now do work in another task params["subscriber_keys"] = [key.urlsafe() for key in self.subscribers] safe_enqueue(work_url, params=params, **kwargs)