2
# Copyright (C) 2015 Canonical
4
# This program is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
from core_image_builder import constants
24
logger = logging.getLogger(__name__)
27
'CoreImageResultBuilder',
28
'create_connection_from_config',
32
def create_connection_from_config(config):
33
"""Create a connection given a config object.
35
'config' can either be a ConfigParser instance, or a nested dictionary.
38
amqp_uris = config.get('amqp', 'uris').split()
39
return kombu.Connection(amqp_uris)
42
class CoreImageResultBuilder(object):
44
"""A callable that knows how to publish results from this service.
46
For now we're using a simple queue, but this can easily be extended to use
47
a full-blown topic exchange in the future.
51
def __init__(self, connection):
52
self.connection = connection
54
def __call__(self, payload):
55
"""Take 'payload' and enqueue it on the rabbit queue."""
56
queue = self.connection.SimpleQueue(
57
"core.tests.{}".format(constants.API_VERSION)