コード例 #1
0
ファイル: views.py プロジェクト: adamchainz/cyme
    def dispatch(self, request, app, rest):
        gd = lambda m: getattr(request, m)
        queue, url = self.prepare_path(rest)
        app = apps.get(app)
        broker = app.get_broker()
        method = request.method.upper()
        pargs = {}
        if queue:
            queue = queues.get(queue)
            pargs.update(exchange=queue['exchange'],
                         exchange_type=queue['exchange_type'],
                         routing_key=queue['routing_key'])
        params = gd(method) if method in self.get_methods else gd('GET')
        data = gd(method) if method not in self.get_methods else None

        with broker.producers.acquire(block=True) as producer:
            publisher = celery.amqp.TaskPublisher(
                            connection=producer.connection,
                            channel=producer.channel)
            result = webhook.apply_async((url, method, params, data),
                                         publisher=publisher, retry=True,
                                         **pargs)
            return self.Accepted({'uuid': result.task_id, 'url': url,
                                  'queue': queue, 'method': method,
                                  'params': params, 'data': data,
                                  'broker': producer.connection.as_uri()})

        def _parse_path_containing_url(self, rest):
            m = self.re_url_in_path.match(rest)
            if m:
                first, scheme, last = m.groups()
                if scheme:
                    return first, scheme + last
                return first, None
            return rest, None
コード例 #2
0
    def dispatch(self, request, app, rest):
        gd = lambda m: getattr(request, m)
        queue, url = self.prepare_path(rest)
        app = apps.get(app)
        broker = app.get_broker()
        method = request.method.upper()
        pargs = {}
        if queue:
            queue = queues.get(queue)
            pargs.update(exchange=queue['exchange'],
                         exchange_type=queue['exchange_type'],
                         routing_key=queue['routing_key'])
        params = gd(method) if method in self.get_methods else gd('GET')
        data = gd(method) if method not in self.get_methods else None

        with broker.producers.acquire(block=True) as producer:
            publisher = celery.amqp.TaskPublisher(
                connection=producer.connection, channel=producer.channel)
            result = webhook.apply_async((url, method, params, data),
                                         publisher=publisher,
                                         retry=True,
                                         **pargs)
            return self.Accepted({
                'uuid': result.task_id,
                'url': url,
                'queue': queue,
                'method': method,
                'params': params,
                'data': data,
                'broker': producer.connection.as_uri()
            })

        def _parse_path_containing_url(self, rest):
            m = self.re_url_in_path.match(rest)
            if m:
                first, scheme, last = m.groups()
                if scheme:
                    return first, scheme + last
                return first, None
            return rest, None
コード例 #3
0
ファイル: views.py プロジェクト: adamchainz/cyme
 def get(self, request, app, name=None):
     return queues.get(name) if name else queues.all()
コード例 #4
0
 def get(self, request, app, name=None):
     return queues.get(name) if name else queues.all()