Pymongo collection object fails when i try to run my tasks with celery. I guess it couldn't serialize it. What should i do? By the way i tried pickle but it doesn't help me.
PS: I don't want to make global db import to this module.
'Collection' object is not callable. If you meant to call the 'getnewargs' method....
Sample code is below. module.py
from celery.contrib.methods import task_method
class Some_Class(object):
"""docstring for Some_Class"""
def __init__(self, db):
super(Some_Class, self).__init__()
self.db = db # This object causes 'Collection' object is not callable
#db is a pymongo collection object from db.py
@app.task(filter=task_method) # Celery task
def add(self):
"""
db.insert({'some_key':'some_value'})
"""
return 3
db.py
from pymongo import MongoClient
db = MongoClient()['test']['collection']
You should not be serializing collection objects. Instead store collection name and obtain collection object from within the task.
Collection objects require the associated established MongoClient object graph to be usable. Without the MongoClient, even if you somehow managed to deserialize a collection object, it wouldn't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With