Adding to cloud search from celery doesn't work

57 views Asked by At

I'm using Cloudsearch for searching on my website. When I try to add/remove items from the index, it works...as long as I don't do it as a asynch task in celery. If I do it outside of that it works perfectly. I was wondering if someone can point me in the right direction?

My code is below:

from boto.cloudsearch2.layer2 import Layer2

@task
def add_employer(emp_id):
    conn = Layer2(aws_access_key_id=AWS_ACCESS_KEY_ID,
                  aws_secret_access_key=AWS_SECRET_ACCESS_KEY)
    domain = conn.lookup("mydomain")

    emp = # the value
    emp_map = {
        "name": emp.name,
        "id": emp.id,
        "url": emp.url
    }

    domain.layer1.sign_request = True
    doc_service = domain.get_document_service()
    doc_service.add(emp.id, emp_map)
    doc_service.commit()

is there something wrong with this code? I called the exact method with and without celery. It works consistently without celery and never with celery.

0

There are 0 answers