Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
926 views
in Technique[技术] by (71.8m points)

asynchronous - How to pass variable rate_limit value to celery task in python?

How do I pass my variable value to decorator for rate limit of celery task?

Here goes the code:

INDIVIDUAL_RATE_LIMIT = None

class BulkTask(Task):
    def run(self, quota):
        global INDIVIDUAL_RATE_LIMIT
        individual_tasks_list = get_individual_tasks_list()
        for individual_task in individual_tasks_list:
            rate_limit = get_rate_limit_for_individual_task(quota, individual_task.id)
            INDIVIDUAL_RATE_LIMIT = rate_limit 
            individual_task.delay(individual_task.id)

@app.task(rate_limit=INDIVIDUAL_RATE_LIMIT)
def individual_task(individual_task_id):
    print(f'Individual task id: {individual_task_id}, at time: {datetime.now()}')

The problem here is the celery task takes the value of INDIVIDUAL_RATE_LIMIT as None. I somehow want to send the value of INDIVIDUAL_RATE_LIMIT from the for loop to celery task.

question from:https://stackoverflow.com/questions/65847502/how-to-pass-variable-rate-limit-value-to-celery-task-in-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...