我有一个celery web抓取任务,我想将所有创建的子对象返回给父对象。如何将这些ID返回给父母?
我想做的事的粗略例子
@task
def scrape_page(url):
page = Page.objects.create(
name='new_page'
)
response = requests.get(url)
children = parse_children(response)
for child in children:
result = scrape_child.delay(child.url)
page.childen.add(result)
@task
def scrape_child(url):
response = requests.get(url)
parsed = parse_child(response)
child = Child.objects.create(**parsed)
return child
答案 0 :(得分:0)
您不应该等待任务中延迟的任务,可以与VBO: [p1_x, p1_y, p1_z, c1_x, c1_y, c1_z, p2_x, p2_y, p2_z, c2_x, c2_y, c2_z, ...]
| |
| |
| |
start of vertex 1 start of vertex 2
IBO: [0, 1, 3, 1, 0, 4, ...]
同步调用该任务,但这不会调用单独的任务。
编辑:我找到了文档,请参见Avoid launching synchronous subtasks
也许您应该使用group。一种方法是延迟一组.apply()
任务并发送父scrape_child
page_id