Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enter arguments of celery jobs into database to be queried; using mysql

I am using MySql as result backend for celery. I want to store program arguments in DB too.

For example:

add.apply_async(args=[num1, num2, user]

In this case I want to store user argument in DB, so that I can query later.

Currently, I return arguments provided which is stored in DB.

def add(num1, num2, user):
    return [num1+num2, user]

However when the task is running state, user is not inserted and I am unable to query it in DB. Is there any solution/hack for this?

like image 481
Rajs123 Avatar asked Jul 13 '16 08:07

Rajs123


1 Answers

Are you only using MySql as a result backend, or are you using it for the queue as well (which I wouldn't recommend)? If you're using it for a queue, the args should be in the database as soon as the task has been sent. Otherwise, the task result can't be stored until after the task has finished.

If you need the arguments to be query-able while the task is running, you'll need to manually insert them into a DB table at the start of your task. If you want them to be query-able before the task starts, you'll need to insert them into a DB table right before calling apply_async.

like image 183
Seán Hayes Avatar answered Oct 14 '22 01:10

Seán Hayes