开发者

Celery-Django: Unable to execute tasks asynchronously

I'm trying to run some tasks in the background while users browse my site, but whenever I call a function using Celery it seems to be executed synchronously instead of asynchronously.

e.g., when I call function.delay() the entire site hangs until function.delay() returns. Other methods of calling functions in a similar manner (apply_async, subtasks) exhibit the same problem.

I'm guessing something in either Django or Celery is misconfigured, but I don't know what it is.

Celery configuration in settings.py:

import djcelery
djcelery.setup_loader()

CELERY_RESULT_BACKEND = "amqp"
CELERYBEAT_SCHEDULER = "djcelery.schedulers.DatabaseScheduler"
BROKER_HOST = "localhost"
BROKER_PORT = 5672
BROKER_USER = "test"
BROKER_PASSWORD = "test"
BROKER_VHOST = "testhost"

TEST_RUNNER = "djcelery.contrib.test_runner.run_tests"

CELERY_IMPORTS = ("myapp.tasks",)

BROKER_BACKEND = "memory"
CELERY_ALWAYS_EAGER = True

Trying to start the Celery daemon wi开发者_开发技巧th "./manage.py celeryd", I get the following output:

[2011-09-23 09:25:38,026: WARNING/MainProcess]  

 -------------- celery@iMac.local v2.2.7
---- **** -----
--- * ***  * -- [Configuration]
-- * - **** ---   . broker:      memory://test@localhost:5672/testhost
- ** ----------   . loader:      djcelery.loaders.DjangoLoader
- ** ----------   . logfile:     [stderr]@WARNING
- ** ----------   . concurrency: 4
- ** ----------   . events:      OFF
- *** --- * ---   . beat:        OFF
-- ******* ----
--- ***** ----- [Queues]
 --------------   . celery:      exchange:celery (direct) binding:celery


[2011-09-23 09:25:38,035: WARNING/MainProcess] celery@iMac.local has started.


Try removing

CELERY_ALWAYS_EAGER = True

You are explicitly asking celery to execute tasks synchronously. It'll always wait for the result. This setting is useful for writing unit tests etc.

Read http://ask.github.com/celery/configuration.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜