Celery manually decoding message body in python

16 Views Asked by At

I have a celery queue with Redis as broker. I want to pick up tasks from this queue directly from redis by using Brpop in python.

This works correctly but celery encodes the task input data in a base64 string. So I have a python function that decodes this into a json object since thats the data structure I am expecting to get from the queue:

def decode():
    queue_name, task_input = r.brpop()
    task_input = json.loads(task_input)
    decoded = b64decode(task_input['body']).decode('utf-8')
    return decoded

this decoder works, but I noticed that all the decoded output have this format:

[[],{<my json key value pairs>}]

I.e. its a list of 2 elements, the first element is an empty list and the second is the expected data.

Why is there an empty list? Celery must be adding some data to the message.

Now I can adjust the decoder function to just grab the dict that I want, but is there a celery function that parses the task from this format?

0

There are 0 best solutions below