Merge lp:~abentley/launchpad/celery-rabbit-config into lp:launchpad

Proposed by Aaron Bentley on 2012-04-04
Status: Merged
Merged at revision: 15066
Proposed branch: lp:~abentley/launchpad/celery-rabbit-config
Merge into: lp:launchpad
Prerequisite: lp:~abentley/launchpad/celery-everywhere
Diff against target: 33 lines (+10/-2)
2 files modified
lib/lp/services/job/celeryconfig.py (+6/-1)
lib/lp/services/job/tests/__init__.py (+4/-1)
To merge this branch: bzr merge lp:~abentley/launchpad/celery-rabbit-config
Reviewer Review Type Date Requested Status
Abel Deuring (community) code 2012-04-04 Approve on 2012-04-04
Review via email: mp+100813@code.launchpad.net

Commit Message

Use all configured RabbitMQ settings.

Description of the Change

= Summary =
Fix bug #973463: Celery does not use specified virtual host

== Proposed fix ==
Specify all Launchpad's RabbitMQ settings individually. Convert to a URL when running celeryd as a subprocess.

== Pre-implementation notes ==
None

== Implementation details ==
URL construction is a pain. It's easier to use the BROKER_* settings, even though we have to split the port from the host.

We need a URL to pass to the --broker parameter when running celeryd, since the individual settings can't be overridden. But we can use the connection itself to generate the URL, which should be authoritative.

== Tests ==
bin/test -t Celery

== Demo and Q/A ==
Enable branch scan jobs by setting the "jobs.celery.enabled_classses" feature flag to "BranchScanJob". Push a branch to qastaging. Run "sudo rabbitmqctl -p qastaging.launchpad.net list_queues name messages consumers memory". This should list a "standard" queue with 1 message.

(Restore the jobs.celery.enabled_classes feature flag to its previous value.)

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/services/job/runner.py
  lib/lp/code/interfaces/branch.py
  lib/lp/services/job/interfaces/job.py
  lib/lp/code/model/tests/test_branchjob.py
  lib/lp/testing/factory.py
  lib/lp/code/model/branch.py
  lib/lp/code/model/tests/test_branchtarget.py
  lib/lp/services/job/celeryconfig.py
  lib/lp/code/model/tests/test_branchpuller.py
  lib/lp/services/job/tests/__init__.py
  lib/lp/code/model/tests/test_branch.py
  lib/lp/code/model/branchjob.py

To post a comment you must log in.
Abel Deuring (adeuring) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/services/job/celeryconfig.py'
2--- lib/lp/services/job/celeryconfig.py 2012-04-04 15:33:33 +0000
3+++ lib/lp/services/job/celeryconfig.py 2012-04-04 15:33:34 +0000
4@@ -1,5 +1,10 @@
5 from lp.services.config import config
6-BROKER_URL = "amqplib://%s" % config.rabbitmq.host
7+host, port = config.rabbitmq.host.split(':')
8+BROKER_HOST = host
9+BROKER_PORT = port
10+BROKER_USER = config.rabbitmq.userid
11+BROKER_PASSWORD = config.rabbitmq.password
12+BROKER_VHOST = config.rabbitmq.virtual_host
13 CELERY_IMPORTS = ("lp.services.job.celeryjob", )
14 CELERY_RESULT_BACKEND = "amqp"
15 CELERY_QUEUES = {
16
17=== modified file 'lib/lp/services/job/tests/__init__.py'
18--- lib/lp/services/job/tests/__init__.py 2012-04-04 15:33:33 +0000
19+++ lib/lp/services/job/tests/__init__.py 2012-04-04 15:33:34 +0000
20@@ -23,9 +23,12 @@
21 """
22 from lp.services.job.celeryjob import CeleryRunJob
23 from lazr.jobrunner.tests.test_celerytask import running
24+ # convert config params to a URL, so they can be passed as --broker.
25+ with CeleryRunJob.app.broker_connection() as connection:
26+ broker_uri = connection.as_uri(include_password=True)
27 cmd_args = (
28 '--config', 'lp.services.job.celeryconfig',
29- '--broker', CeleryRunJob.app.conf['BROKER_URL'],
30+ '--broker', broker_uri,
31 '--concurrency', '1',
32 '--loglevel', 'INFO',
33 '--queues', queue,