You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@app.task
def _add(a, b):
return a + b
@app.task
def sumall(a, b, c, d):
return (_add.s(a,b) | _add.s(c) | _add.s(d))()
And: Celery configured to use mongodb as backend database but with different database other than celery (Issue does not happen if celery is selected as database)
When: I run the add task in one process and get the status by id in another process (Note: in same process issue does not happen. )
result = sumall.delay(1,2,3,4)
print(result.id)
Take the id from above process and print the status in another process using same celery settings as worker and process1 (that initiated sumall task)
result = app.AsyncResult('636c865f-df44-4e82-9f3f-d88cf13cbc13').get() # Works (uses correct db)
result.get() # Hangs . Uses celery db instead of 'celery2' database.
Then:
second process hangs forever when trying to get second result in the chain.
Workaround-1:
result = app.AsyncResult('636c865f-df44-4e82-9f3f-d88cf13cbc13').get() # Works (uses correct db)
app.AsyncResult(result.id).get() # This time it uses correct db.
Workaround-2:
Do not change default database.
The text was updated successfully, but these errors were encountered:
After debugging through celery source, here is what I found :
I did figure out how celery is initializing the backend using default_app. https://github.com/celery/celery/blob/master/celery/_state.py#L83 However, _tls.current_app is always None in my case. Even though set_as_current is True for my celery app object. As a result it fall backs to default app (there by changing the database)
Setting current_app did help to solve the database issue. However there seems to be a bug with host initialization during de-serialization process in MongoBackend. Even after using current_app, celery was trying to use 'localhost' as host. Here is a patch to fix this issue:
Given:
Celery version: 3.1.16
And:
Celery task that returns asyncresult. E.g:
And: Celery configured to use mongodb as backend database but with different database other than celery (Issue does not happen if celery is selected as database)
When: I run the add task in one process and get the status by id in another process (Note: in same process issue does not happen. )
Take the id from above process and print the status in another process using same celery settings as worker and process1 (that initiated sumall task)
Then:
second process hangs forever when trying to get second result in the chain.
Workaround-1:
Workaround-2:
Do not change default database.
The text was updated successfully, but these errors were encountered: