简体   繁体   English

使用 Celery,在单个 celery 任务中执行 URL 列表。 可能吗?

[英]Using Celery, execute a list of URLs in a single celery task. Is it Possible?

views.py视图.py

urls=["https//:.....com,https//:.....com,etc.."]
for i in urls:
   r=process.delay(i)

When I'm calling the celery task it execute separate task.当我调用 celery 任务时,它执行单独的任务。 How to execute the set of lists in a single celery task?如何在单个 celery 任务中执行列表集?

tasks.py任务.py

@app.task
def process(url):
    r = requests.get(url, allow_redirects=True)
    return r

You can pass a group of URLs or even the whole list to the celery task.您可以将一组 URL 甚至整个列表传递给 celery 任务。 But this doesn't make much sense as we haven't actually taken advantage of the parallelized outgoing requests since each URL would be accessed serially, one after the other.但这并没有多大意义,因为我们实际上并没有利用并行的传出请求,因为每个 URL 将一个接一个地被串行访问。

views.py视图.py

urls=["https//:.....com", "https//:.....com", ...]
r = process.delay(urls)

tasks.py任务.py

@app.task
def process(urls):
    results = []
    for url in urls:
        r = requests.get(url, allow_redirects=True)
        results.append(r)
    return results

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM