如何解决如何使用Rabbitmq消息代理将多个REST API调用与celery并行化?
我只是芹菜的初学者。我正在尝试构建一个应用程序,在该应用程序中,我需要对从数据库中获取的用户进行不同的rest API调用。
这是我的任务。py:
import sys
sys.path.append("../..")
from my_tests.celery_queue.test_celery import app
from mongo_db_cache.database import *
from mongo_db_cache.api_requests import *
@app.task(name='my_tests.celery_queue.tasks.api_req1',queue="api_req1")
def api_req1(customer_nme):
if customer_nme is not None:
api_requests = APIRequests(customer_nme)
request_status = api_requests.get_address()
@app.task(name='my_tests.celery_queue.tasks.api_req2',queue="api_req2")
def api_req2(customer_nme):
if customer_nme is not None:
api_requests = APIRequests(customer_nme)
request_status = api_requests.get_tenant()
@app.task(name='my_tests.celery_queue.tasks.api_req3',queue="api_req3")
def api_req3(customer_nme):
if customer_nme is not None:
api_requests = APIRequests(customer_nme)
request_status = api_requests.get_dashboard_info()
if __name__ == '__main__':
customer_database = DataBase()
customer_names = customer_database.get_customer_name()
for cust in customer_names:
# first api request
api_req1.delay(cust)
# second api request
api_req2.delay(cust)
# third api request
api_req3.delay(cust)
说,从数据库中提取了100个用户,那么这总共需要进行100*3=300
个API请求。如何通过将这些API请求调用与celery并行化来提高性能?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。